Community
Participate
Working Groups
Build ID: I20070625-1500 Steps To Reproduce: writing the following class, will detect an unreachable code part. public class Test { private static final boolean PREDICATE = false; public Object test() throws Exception { if (PREDICATE) { Iterator i = new HashSet().iterator(); //is not detected as unreachable test:while (i.hasNext()) { //the test:-Label is essential to reproduce this bug } return null; //is detected as unreachable } return null; } } In fact this code is statically unreachable. Strictly regarded, the unreachable code part starts at the beginning of the conditional block. But this is not a reason to reject compilation. If we omit the Label "test" from the while-statement, everything is fine. More information:
Reproduced. Indeed this is inconsistent. Thanks for reporting it.
This regression got introduced during 3.3.
Likely a consequence of fix for bug 134848
Maxime - pls redo fix for bug 134848. It seems that the line "statementInfo.mergedWith(labelContext.initsOnBreak)" (in LabelStatement) should always be executed no matter what. Then the null info in some case could be managed separately afterwards. Currently the null info handling is breaking the standard flow analysis. I would also want a fix for 3.3.2.
There should be no difference between the test() and test1(): import java.util.*; public class X { private static final boolean PREDICATE = false; public Object test() throws Exception { if (PREDICATE) { Iterator i = new HashSet().iterator(); // is not detected as unreachable test: while (i.hasNext()) { // the test:-Label is essential to reproduce this bug } return null; // is detected as unreachable } return null; } public Object test2() throws Exception { if (PREDICATE) { Iterator i = new HashSet().iterator(); // is not detected as unreachable while (i.hasNext()) {} return null; // is detected as unreachable } return null; } }
Released FlowAnalysisTest#48 (inactive) and 49 in HEAD.
Created attachment 78443 [details] Suggested fix Patch for HEAD. Tests pass. Kent could you please review it?
Released for 3.4 M3. Setting target to 3.3.2 per Philippe's comment #4.
Reopening for 3.3.2.
Created attachment 79879 [details] R3_3_MAINTENANCE patch Essentially porting the changes of the test infrastructure. The code change in core is the same as for HEAD.
Released for 3.3.2.
Verified for 3.4M3 using I20071029-0010 build.
Sorry, I should not have set this bug as VERIFIED...
...but set the status whiteboard instead!
This is a regression introduced when adding support for null analysis. The regression affects mandatory flow analysis diagnosis (not optional null analysis). This is quite severe.
+1 for 3.3.2
Verified for 3.3.2 using build M20080123-0800.