Community
Participate
Working Groups
When "Correct Indentation" is active as a save action, lines following a ternary operator (with line breaks) are indented one level too much (aligned with the ternary operator). To reproduce: Start Eclipse 4.10.0 with a new workspace. Configure save action: Open Window -> Preferences Select Java -> Editor -> Save Actions Tick "Perform the selected actions on save" Tick "Additional actions" Click "Configure..." Tick "Correct Indentation" Create a new Java project and add this class: // begin class public class TernaryFormatter { public int doSomething(String foo, String bar) { int retval = "".equals(bar) ? foo.length() : foo.hashCode(); System.out.println("Why am I indented?"); return retval; } } // end class Edit the file (e.g. add one space somewhere). Save the file. Result: The line 'System.out.println("Why am I indented?");' and following are indented too far right, aligned with the question mark.
A workaround is to wrap the entire ternary expression in parentheses: int retval = ("".equals(bar) ? foo.length() : foo.hashCode());
*** This bug has been marked as a duplicate of bug 65463 ***