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.

Bug 257910 - Refactoring (Invert if) modifies/breaks logic/changes code behaviour
Summary: Refactoring (Invert if) modifies/breaks logic/changes code behaviour
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.2
Hardware: PC Windows 7
: P2 normal with 1 vote (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-09 16:32 UTC by bugmenot1
Modified: 2016-03-31 01:42 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugmenot1 2016-02-09 16:32:53 UTC
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
Comment 1 Ralph Ruijs 2016-03-03 11:55:21 UTC
Invert If is a Java Hint, reassigning. Please evaluate, thanks!
Comment 2 Jiri Prox 2016-03-24 14:10:19 UTC
reproducible
Comment 3 Svata Dedic 2016-03-30 07:16:12 UTC
Fixed in jet-main#fa6cf6fbc4f9, tests added.
Comment 4 Quality Engineering 2016-03-31 01:42:57 UTC
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