Community
Participate
Working Groups
Overview: If I have an inline comment inside a lambda it gets incorrectly formatted Steps To Reproduce: - Create a simple test that has an inline comment inside a lambda, like so: Executors.newSingleThreadExecutor().execute(() -> { // this is a comment System.err.println("this shouldn't be here"); }); Actual results: Not sure if bugzilla will format this correctly but the above example is what I see. The line under the comment is shifted to the right when it shouldn't be. Expected results: The line under the comment should be directly under the comment in the same column. I would also expect the closing brace and parenthesis to be shifted over to the left to align with where the initial statement begins. Build: Has been happening on Kepler with java 8 patches as well as the 4.4 nightly/integration builds with java 8 added (on a Mac) See also: bug 435241 - Very similar behavior but with if/else statements
Here's another example of bad behavior: Executors.newSingleThreadExecutor().execute(() -> { System.err.println("this is ok"); // this is a comment System.err.println("this shouldn't be here"); System.err.println("this shouldn't be here"); System.err.println("this shouldn't be here"); // another comment System.err.println("this shouldn't be here"); // text only get shifted once for the whole lambda block }); When using multiline comments /* */, everything is fine.
I stumbled upon the same problem. After a little investigation, I found that the indentation bug appears only in lambdas within a chained method call, not in simple method calls: new Sandbox().test(i -> { // test System.out.println("extra indent"); }); new Sandbox().test(i -> { System.out.println("no bug"); }); testStatic(i -> { //test System.out.println("no bug"); }); testStatic(i -> { System.out.println("no bug"); });
This problem no longer occurs, (probably) after the formatter redesign. *** This bug has been marked as a duplicate of bug 303519 ***
verified on Version: 4.9 Build id: I20180731-1305