Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java console bug under windows

The following Code

System.out.println("Start");
String s = "";
//936 * 5 = 4680 characters
for (int i = 0; i < 937; i++){
    s += "1234 ";
}
System.out.println(s);
System.out.println("End");

produces an empty line between "Start" and "End" on the java console under windows, but works as expected when running MacOS or Linux. Same applies when writing to a file instead of using sysout. I've tried multiple windows machines. It doesn't matter whether I execute the method through eclipse or via cmd.

When you change "1234 " to "1234," or "12g4 " or when the number of runs is more/less than 936, it works as expected with all OS.

Can anybody confirm this/is there a known bug concerning this issue?

like image 210
dschihejns Avatar asked Dec 02 '11 09:12

dschihejns


1 Answers

I can reproduce this as well, under Windows 7. It looks like a limitation due to the OS in SWT, and it seems to have been around for a very long time (2002). It's marked as WONTFIX. See GC#drawString, drawText don't render more than 10923 characters per line correctly. So this is a known bug.

The workaround is to go to the Workspace->Preferences->Run/Debug->Console and set the Fixed width console to be something like 4000 chars. This will wrap your lines after 4000 characters, which is a pain, but at least you'll get all of your output.

I have tried Galileo (3.5), Helios (3.6) and Indigo (3.7), and all exhibit the behaviour, but wierdly, Galileo & Helios have a limit = 818 (4090 chars) and Indigo = 936 (4680) chars as the OP said. The 4090 makes me think of a OS limit (the next would be 4090 + 5 + crlf, > 4096), which matches with the bugs raised in Eclipse/SWT. I can't explain why there is a difference in the number of characters accepted. I can only suggest that it's something in the OS.

There are a number of duplicate bugs raised in Eclipse:

  1. Bug 19850 - Large string printed in Console overstrikes/disappears depending on length
  2. Bug 44866 - Truncate long strings in variables view
  3. Bug 104588 - Unreadable console output under certain conditions

Everything seems to have been a consequence of: Bug 11601 - console hangs while displaying long strings without crlf

like image 69
Matthew Farwell Avatar answered Oct 04 '22 02:10

Matthew Farwell