[PATCH] Pretty printing for loops

Jonathan Gibbons jonathan.gibbons at oracle.com
Mon Jan 5 18:59:57 UTC 2015

On 12/05/2014 12:45 AM, Tobias Werth wrote:
> Hi,
> (if this is not the correct mailing list to submit those patches, please
> tell me which one to use instead)
> I stumbled upon a bug in the javac pretty printer. It misses a null
> check while pretty printing for loops causing to produce invalid code.
> The attached patch contains a fix including a test that fails before and
> works after applying the patch.
> Cheers,
> Tobi


Thank you for your patch. In reviewing the code, I note that the test 
will probably fail on Windows, because of the "newline issue".
javac Pretty will render the source code using platform newlines, which 
means the assertEquals on line 73 will fail.

The general recommendation in cases like this is to do something like:

-  81         return sw.toString();
+             String NL = System.getProperty("line.separator");
+  81         return sw.replace(NL, "\n").toString();

-- Jon

More information about the compiler-dev mailing list