### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java,v retrieving revision 1.10 diff -u -r1.10 NullInfoRegistry.java --- compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java 7 Mar 2009 01:08:10 -0000 1.10 +++ compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java 20 Jul 2010 16:40:57 -0000 @@ -319,7 +319,7 @@ // prot. non null & ((a2 = this.nullBit2) | (a4 = this.nullBit4)); // null or unknown - m2 = s1 & (s2 = this.nullBit2) & (s3 ^ s4) + m2 = s1 & (s2 = this.nullBit2) & (s3 ^ s4) // TODO(stephan): potential typo: should this be "s2 = source.nullBit2"??? // prot. null & ((a3 = this.nullBit3) | a4); // non null or unknown @@ -336,6 +336,18 @@ source.nullBit2 &= (nm1 = ~m1) & ((nm2 = ~m2) | a4); source.nullBit3 &= (nm1 | a2) & nm2; source.nullBit4 &= nm1 & nm2; + // any variable that is (pot n, pot nn, pot un) at end of try (as captured by *this* NullInfoRegistry) + // has the same uncertainty also for the mitigated case (function result) + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 - [compiler] [null] Whitebox issues in null analysis + // and org.eclipse.jdt.core.tests.compiler.regression.NullReferenceTest.test0536_try_finally() + long x = ~this.nullBit1 & a2 & a3 & a4; // x is set for all variable ids that have state 0111 (pot n, pot nn, pot un) + if (x != 0) { + // restore state 0111 for all variable ids in x: + source.nullBit1 &= ~x; + source.nullBit2 |= x; + source.nullBit3 |= x; + source.nullBit4 |= x; + } } if (this.extra != null && source.extra != null) { int length = this.extra[2].length, sourceLength = source.extra[0].length; Index: compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java,v retrieving revision 1.65 diff -u -r1.65 UnconditionalFlowInfo.java --- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 24 Feb 2010 20:12:40 -0000 1.65 +++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 20 Jul 2010 16:40:59 -0000 @@ -63,6 +63,7 @@ 0100 pot. null 0101 pot. n & pot. un 0110 pot. n & pot. nn + 0111 pot. n & pot. nn & pot. un 1001 def. unknown 1010 def. non null 1011 pot. nn & prot. nn #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java,v retrieving revision 1.9 diff -u -r1.9 NullReferenceImplTests.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java 28 Apr 2009 17:17:38 -0000 1.9 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java 20 Jul 2010 16:41:03 -0000 @@ -96,7 +96,7 @@ 011001 011010 011011 - 011100 + 011100 pot. n & pot. nn & pot. un 011101 011110 011111 Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v retrieving revision 1.95 diff -u -r1.95 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 16 Mar 2010 14:36:08 -0000 1.95 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 20 Jul 2010 16:41:17 -0000 @@ -5484,6 +5484,35 @@ ""); } +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 - [compiler] [null] Whitebox issues in null analysis +// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information +public void test0536_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar () { return null; }\n" + + " void foo() {\n" + + " X x = new X();\n" + + " try {\n" + + " x = null;\n" + + " x = new X();\n" + // if this throws an exception finally finds x==null + " x = bar();\n" + + " } finally {\n" + + " x.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " x.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable x may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + // null analysis -- try/catch public void test0550_try_catch() { this.runConformTest(