| Summary: | Wrong null optimisation with loops in try/catch | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Matthew Wilson <mj.wilson.uk> |
| Component: | Core | Assignee: | Ayushman Jain <amj87.iitr> |
| Status: | VERIFIED DUPLICATE | QA Contact: | |
| Severity: | major | ||
| Priority: | P3 | CC: | amj87.iitr, srikanth_sankaran |
| Version: | 3.7 | ||
| Target Milestone: | 3.6.1 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
This has been fixed in bug 321926. With a newer build, I get the expected output "Expected 1" and "Expected 2". *** This bug has been marked as a duplicate of bug 321926 *** Verified for 3.7 M3 using build I20101025-1800 |
Build Identifier: I20100608-0911 In certain circumstances with loops in try/catch statements, the Eclipse compiler is outputting an "aconst_null" instead of an "aload" for variables it erroneously believes are always null. This bug has two effects: 1. The compiler incorrectly warns that a variable can only ever be null (when, in fact, it can be non-null). 2. The result is wrong. Using javac gives the correct result. The differences in the byte-code between Eclipse and javac are obvious. Try this example program. From my tests, it seems that a 'while', 'do...while', or 'for' loop is required. The program should print "Expected 1" and "Expected 2". The exception type needs to be a checked Exception that is a subclass of Exception (i.e. not Exception itself). public class NullFailure { public static void main( final String[] args ) { broken1(); broken2(); } private static void broken1() { NullFailure object = null; try { object = new NullFailure(); do { throw new CloneNotSupportedException(); } while ( false ); } catch ( CloneNotSupportedException exception ) { if ( object != null ) { System.out.println( "Expected 1" ); } } } private static void broken2() { NullFailure object = null; int count = 0; try { object = new NullFailure(); while ( count == 0 ) { throw new CloneNotSupportedException(); } // this line is required object = null; } catch ( CloneNotSupportedException exception ) { if ( object != null ) { System.out.println( "Expected 2" ); } } } } Reproducible: Always Steps to Reproduce: 1. Compile the program given in the Eclipse IDE. 2. Run the program and witness that the results are not as expected. 3. Compile the program given with javac. 4. Run the program and witness that the results are correct.