### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.50 diff -u -r1.50 UnconditionalFlowInfo.java --- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 27 Feb 2006 11:44:01 -0000 1.50 +++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 27 Feb 2006 17:07:05 -0000 @@ -1335,6 +1335,12 @@ b1 & nb2 & (a3 | b3)); this.nullAssignmentValueBit2 = a4 | b4; + + // WORK recode if tests succeed + this.nullAssignmentValueBit1 &= + ~(a1 & na2 & na3 & a4 & nb1 & b2 & nb3 & nb4 + | ~a1 & a2 & na3 & na4 & b1 & nb2 & nb3 & b4); + if (coverageTestFlag && coverageTestId == 37) { this.nullAssignmentValueBit2 = ~0; } @@ -1438,6 +1444,12 @@ b1 & nb2 & (a3 | b3)); this.extra[5][i] = a4 | b4; + + // WORK recode if tests succeed + this.extra[4][i] &= + ~(a1 & na2 & na3 & a4 & nb1 & b2 & nb3 & nb4 + | ~a1 & a2 & na3 & na4 & b1 & nb2 & nb3 & b4); + thisHasNulls = thisHasNulls || this.extra[5][i] != 0 || this.extra[2][i] != 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.10 diff -u -r1.10 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 27 Feb 2006 11:29:31 -0000 1.10 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 27 Feb 2006 17:07:07 -0000 @@ -2114,6 +2114,121 @@ "----------\n"); } +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 +// invalid analysis when redundant check is done +public void test0333_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = new Object();\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " o.toString();\n" + // quiet asked + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "----------\n"); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 +// invalid analysis when redundant check is done - variant +public void test0334_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = new Object();\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " else {\n" + + " o.toString();\n" + // must complain anyway (could be quite distant from the if test) + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "The variable o 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 8)\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"); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129581 +// this is a limit of the fix for bug 128014 - calls for a nuance +// between potential null and tainted null +public void _test0335_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + + "----------\n"); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 +// invalid analysis when redundant check is done - variant +public void test0336_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " else {\n" + + " o.toString();\n" + // must complain anyway (could be quite distant from the if test) + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "The variable o 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 8)\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"); +} + // null analysis -- while public void test0401_while() { this.runNegativeTest( @@ -2603,7 +2718,6 @@ } // null analysis -- while -// the second message looks a bit strange public void test0423_while() { this.runNegativeTest( new String[] { @@ -2624,11 +2738,6 @@ " if (o == null) { /* */ }\n" + " ^\n" + "The variable o 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 8)\n" + - " o = null;\n" + - " ^\n" + - "The variable o can only be null; it was either set to null or checked for null when last used\n" + "----------\n"); } @@ -8241,7 +8350,7 @@ {{0,1,0,0},{0,0,1,1},{0,0,1,1}}, {{0,1,0,0},{0,1,0,0},{0,1,0,0}}, {{0,1,0,0},{0,1,1,0},{0,1,1,0}}, - {{0,1,0,0},{1,0,0,1},{0,0,1,1}}, + {{0,1,0,0},{1,0,0,1},{0,0,0,1}}, {{0,1,0,0},{1,0,1,0},{0,1,1,0}}, {{0,1,0,0},{1,0,1,1},{0,0,1,1}}, {{0,1,0,0},{1,1,0,0},{0,0,1,0}}, @@ -8261,7 +8370,7 @@ {{1,0,0,1},{0,0,0,1},{0,0,0,1}}, {{1,0,0,1},{0,0,1,0},{0,0,1,1}}, {{1,0,0,1},{0,0,1,1},{0,0,1,1}}, - {{1,0,0,1},{0,1,0,0},{0,0,1,1}}, + {{1,0,0,1},{0,1,0,0},{0,0,0,1}}, {{1,0,0,1},{0,1,1,0},{0,0,1,1}}, {{1,0,0,1},{1,0,0,1},{1,0,0,1}}, {{1,0,0,1},{1,0,1,0},{0,0,1,1}},