Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 407832

Summary: Java code formatting incorrectly adds newline between "else" and line comment.
Product: [Eclipse Project] JDT Reporter: Garret Wilson <garret>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: VERIFIED DUPLICATE QA Contact:
Severity: minor    
Priority: P3 CC: daniel_megert, jarthana, manoj.palat, mateusz.matela
Version: 4.3   
Target Milestone: 4.8 M5   
Hardware: PC   
OS: Windows 7   
Whiteboard: To be verified for 4.8 M5
Attachments:
Description Flags
Eclipse Java formatting configuration exhibiting problem. none

Description Garret Wilson CLA 2013-05-12 16:31:06 EDT
I like aligned braces, but I also like to put a line comment on the "else" line, like this:

if(expression) //if true
{
  ...
}
else  //if not true
{
  ...
}

Regardless of my formatting settings, Eclipse formatting changes this to (note that the comment after the "else" has been moved to the next line):

if(expression) //if true
{
  ...
}
else
//if not true
{
  ...
}

I have tried all formatting settings combinations, including "insert newline before 'else' in an 'if' statement" and "preserve whitespace between code and line comments". Nothing works.

I have raised the issue with a bounty on StackOverflow, but no one can make this work: http://stackoverflow.com/questions/15592984/

Some have indicated that some of the settings mentioned above worked on Galileo; this I cannot confirm.

It seems this is a clear bug; I want my braces aligned, and I want my whitespace preserved between code and line comments. Eclipse is not complying.
Comment 1 Garret Wilson CLA 2013-05-12 16:32:36 EDT
This was first tested on Eclipse 4.2.2, and I have just confirmed that it does not work in Eclipse 4.3M7, either.
Comment 2 Garret Wilson CLA 2013-05-13 19:01:51 EDT
Created attachment 230906 [details]
Eclipse Java formatting configuration exhibiting problem.

I've added a formatting configuration exported from Eclipse 4.3M7 exhibiting this problem.
Comment 3 Jay Arthanareeswaran CLA 2013-05-14 00:49:10 EDT
Jesper, this is a minor one and you can look at it post 4.3 and Java 8.
Comment 4 Mateusz Matela CLA 2018-01-20 18:16:36 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***
Comment 5 Manoj N Palat CLA 2018-01-22 22:01:22 EST
Verified for Eclipse Photon 4.8 M5 with Build id:  I20180122-0800