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 253847 - [81cat] Java hint: JoinConsecutiveIfsIntoIfElse doesn't work on the test case
Summary: [81cat] Java hint: JoinConsecutiveIfsIntoIfElse doesn't work on the test case
Status: RESOLVED FIXED
Alias: None
Product: qa
Classification: Unclassified
Component: Test Specifications (show other bugs)
Version: 8.1
Hardware: PC Windows 8 x64
: P3 normal (vote)
Assignee: Jiri Prox
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-27 09:45 UTC by cezariusz
Modified: 2015-08-12 15:05 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 cezariusz 2015-07-27 09:45:03 UTC
Link: http://services.netbeans.org/synergy/client/app/#/case/4989/suite/1691

Product Version: NetBeans IDE Dev (Build 201507240001)
Java: 1.8.0_51; Java HotSpot(TM) 64-Bit Server VM 25.51-b03
Runtime: Java(TM) SE Runtime Environment 1.8.0_51-b16
System: Windows 8 version 6.2 running on amd64; UTF-8; pl_PL (nb)

public class JoinConsecutiveIfsIntoIfElse {

    public void method(boolean cond1, boolean cond2) {
        if(cond1) {
            
        } else { //Hint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            } else {
                System.out.println("ko");
            }
            System.out.println("");
        }
        if(cond1) {
            
        } else { //NoHint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            }
            System.out.println("");
        }
    }
}

There is no join hint anywhere in the code.
Comment 1 Svata Dedic 2015-07-30 12:31:23 UTC
the testcase is IMHO wrong;

 if(cond1) {
            
        } else { //NoHint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            }
            System.out.println("");
        }

cannot be joinec into
if (cond1) { ... } else if (cond2) { ...}

since System.out should execute if and only if !cond1 (= regardless of cond2)
Comment 2 Jiri Prox 2015-08-12 15:05:41 UTC
The first case should be
        if(cond1) {
            
        } else { //Hint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            } else {
                System.out.println("ko");
            }
         
        }

Sample file fixed