### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler 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.42 diff -u -r1.42 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 25 Sep 2006 11:21:47 -0000 1.42 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 25 Sep 2006 11:33:44 -0000 @@ -4350,9 +4350,9 @@ ""); } -//null analysis -- try/finally -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 -//variant +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// variant public void test0522_try_finally() { this.runNegativeTest( new String[] { @@ -4450,7 +4450,7 @@ } // null analysis -- try/finally -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150082 public void test0525_try_finally_unchecked_exception() { this.runNegativeTest( new String[] { @@ -4485,7 +4485,7 @@ } // null analysis -- try/finally -// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150082 // variant public void test0526_try_finally_unchecked_exception() { this.runNegativeTest( @@ -4520,7 +4520,7 @@ } //null analysis -- try/finally -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150082 //variant public void test0527_try_finally_unchecked_exception() { this.runNegativeTest( @@ -4551,6 +4551,129 @@ "----------\n"); } +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0528_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " X y = null;\n" + + " try {\n" + + " } finally {\n" + + " if (x != null) { /* */ }\n" + // complain null + " if (y != null) { /* */ }\n" + // complain null as well + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (x != null) { /* */ }\n" + + " ^\n" + + "The variable x can only be null; it was either set to null or checked for null when last used\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (y != null) { /* */ }\n" + + " ^\n" + + "The variable y can only be null; it was either set to null or checked for null when last used\n" + + "----------\n"); +} + +// null analysis -- try finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0529_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " Object o2 = null;\n" + + " try { /* */ }\n" + + " finally {\n" + + " o.toString();\n" + // complain + " o2.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "The variable o can only be null; it was either set to null or checked for null when last used\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " o2.toString();\n" + + " ^^\n" + + "The variable o2 can only be null; it was either set to null or checked for null when last used\n" + + "----------\n"); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0530_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " X y = null;\n" + + " try {\n" + + " x = new X();\n" + + " } finally {\n" + + " x.toString();\n" + + " y.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " x.toString();\n" + + " ^\n" + + "The variable x may be null\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " y.toString();\n" + + " ^\n" + + "The variable y can only be null; it was either set to null or checked for null when last used\n" + + "----------\n"); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0531_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " X x = new X();\n" + + " X y = null;\n" + + " try {\n" + + " } finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " y.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (x != null) {\n" + + " ^\n" + + "The variable x cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " y.toString();\n" + + " ^\n" + + "The variable y can only be null; it was either set to null or checked for null when last used\n" + + "----------\n"); +} + // null analysis -- try/catch public void test0550_try_catch() { this.runConformTest( #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java,v retrieving revision 1.20 diff -u -r1.20 FinallyFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 25 Sep 2006 11:02:53 -0000 1.20 +++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 25 Sep 2006 11:33:46 -0000 @@ -82,36 +82,8 @@ // check inconsistent null checks if (this.deferNullDiagnostic) { // within an enclosing loop, be conservative for (int i = 0; i < this.nullCount; i++) { - Expression expression = this.nullReferences[i]; - LocalVariableBinding local = this.nullLocals[i]; - switch (this.nullCheckTypes[i]) { - case CAN_ONLY_NULL_NON_NULL : - case CAN_ONLY_NULL: - if (flowInfo.isProtectedNonNull(local)) { - if (nullCheckTypes[i] == CAN_ONLY_NULL_NON_NULL) { - scope.problemReporter().localVariableCannotBeNull(local, expression); - } - return; // WORK wrong, test second variable! - } - if (flowInfo.isProtectedNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, expression); - return; - } - break; - case MAY_NULL : - if (flowInfo.isProtectedNonNull(local)) { - return; - } - if (flowInfo.isProtectedNull(local)) { - scope.problemReporter().localVariableCanOnlyBeNull(local, expression); - return; - } - break; - default: - // never happens - } - this.parent.recordUsingNullReference(scope, local, expression, - this.nullCheckTypes[i], flowInfo); + this.parent.recordUsingNullReference(scope, this.nullLocals[i], + this.nullReferences[i], this.nullCheckTypes[i], flowInfo); } } else { // no enclosing loop, be as precise as possible right now @@ -123,22 +95,20 @@ case CAN_ONLY_NULL_NON_NULL : if (flowInfo.isDefinitelyNonNull(local)) { scope.problemReporter().localVariableCannotBeNull(local, expression); - return; + continue; } case CAN_ONLY_NULL: if (flowInfo.isDefinitelyNull(local)) { scope.problemReporter().localVariableCanOnlyBeNull(local, expression); - return; } break; case MAY_NULL : if (flowInfo.isDefinitelyNull(local)) { scope.problemReporter().localVariableCanOnlyBeNull(local, expression); - return; + continue; } if (flowInfo.isPotentiallyNull(local)) { scope.problemReporter().localVariableMayBeNull(local, expression); - return; } break; default: