This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
As you can see, the following code should always print 2: if (false) { if (false) { System.out.println(1); } } else { System.out.println(2); } Move caret to first false, press Alt+Enter, choose Invert if. Result: if (true) { System.out.println(2); } else { if (false) { System.out.println(1); } } Press Alt+Shift+F to format the code. Result: if (true) { System.out.println(2); } else if (false) { System.out.println(1); } Move caret to true, press Alt+Enter, choose Invert if. Result: if (false) if (false) { System.out.println(1); } else { System.out.println(2); } Optional: press Alt+Shift+F to format. Result: if (false) { if (false) { System.out.println(1); } else { System.out.println(2); } } As you can see, the print statement is no longer called. Setting to P1 as I think this qualifies as "data loss: User's data are corrupted or lost". Using this feature introduces bugs which can be hard to find in more complex code. Product Version: NetBeans IDE Dev (Build 201602090002) Java: 1.8.0_71; Java HotSpot(TM) 64-Bit Server VM 25.71-b15 Runtime: Java(TM) SE Runtime Environment 1.8.0_71-b15
Invert If is a Java Hint, reassigning. Please evaluate, thanks!
reproducible
Fixed in jet-main#fa6cf6fbc4f9, tests added.
Integrated into 'main-silver', will be available in build *201603310001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/fa6cf6fbc4f9 User: Svata Dedic <sdedic@netbeans.org> Log: #257910: intermediate Block inserted if else would be wrongly paired with the nested if statement