### 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 29 Jul 2010 13:52:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. + * Copyright (c) 2006, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - [compiler] [null] Whitebox issues in null analysis, see https://bugs.eclipse.org/320170 *******************************************************************************/ package org.eclipse.jdt.internal.compiler.flow; @@ -319,7 +320,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 +337,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 29 Jul 2010 13:52:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - [compiler] [null] Whitebox issues in null analysis, see https://bugs.eclipse.org/320170 *******************************************************************************/ package org.eclipse.jdt.internal.compiler.flow; @@ -63,6 +64,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 29 Jul 2010 13:52:57 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - [compiler] [null] Whitebox issues in null analysis, see https://bugs.eclipse.org/320170 *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -96,7 +97,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.96 diff -u -r1.96 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 22 Jul 2010 14:15:48 -0000 1.96 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 29 Jul 2010 13:53:11 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - [compiler] [null] Whitebox issues in null analysis, see https://bugs.eclipse.org/320170 *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -5484,6 +5485,78 @@ ""); } +// 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/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 +// multiple variables +public void test0537_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar () { return null; }\n" + + " void foo() {\n" + + " X x1 = new X();\n" + + " X x2 = new X();\n" + + " X x3 = new X();\n" + + " try {\n" + + " x1 = null;\n" + + " x2 = null;\n" + + " x1 = new X();\n" + // if this throws an exception finally finds x1==null + " x2 = new X();\n" + // if this throws an exception finally finds x2==null + " x3 = new X();\n" + // if this throws an exception finally still finds x3!=null + " x1 = bar();\n" + + " x2 = bar();\n" + + " } finally {\n" + + " x1.toString();\n" + // complain + " x2.toString();\n" + // complain + " x3.toString();\n" + // don't complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " x1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable x1 may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " x2.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable x2 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + // null analysis -- try/catch public void test0550_try_catch() { this.runConformTest(