Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-04-29 19:38:56 +0000
committerStephan Herrmann2014-04-29 19:45:30 +0000
commita6d7d17b7bc9c61b1990ed86d94864463a8a31d4 (patch)
treecb94fded9cf89ff6b6544f8d2aac7979e00b0b03
parent9f431ffaeff623f7af807c93e73853c08afe96f4 (diff)
downloadeclipse.jdt.core-a6d7d17b7bc9c61b1990ed86d94864463a8a31d4.tar.gz
eclipse.jdt.core-a6d7d17b7bc9c61b1990ed86d94864463a8a31d4.tar.xz
eclipse.jdt.core-a6d7d17b7bc9c61b1990ed86d94864463a8a31d4.zip
Bug 422796 - [compiler][null] boxed boolean reported as potentially nullI20140430-0800
after null test in lazy disjunction
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java90
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java3
3 files changed, 94 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
index b25bc509c3..3efb696341 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
@@ -7204,4 +7204,94 @@ public void testBug403674a() {
) +
"----------\n");
}
+// original test
+public void testBug422796() {
+ runConformTestWithLibs(
+ new String[] {
+ "NullExprTest.java",
+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
+ "import org.eclipse.jdt.annotation.Nullable;\n" +
+ "\n" +
+ "@NonNullByDefault\n" +
+ "public class NullExprTest {\n" +
+ " \n" +
+ " private @Nullable Boolean b() { return null; }\n" +
+ " \n" +
+ " public void testBoolean() {\n" +
+ " Boolean b1 = b();\n" +
+ " boolean b = b1 == null || \n" +
+ " b1; // <-- Previously bugggy: reported potential NPE (*)\n" +
+ " assertTrue(b);\n" +
+ " }\n" +
+ " static void assertTrue(boolean b) {}\n" +
+ "\n" +
+ "}"
+ },
+ getCompilerOptions(),
+ "");
+}
+// inverted logic:
+public void testBug422796a() {
+ runConformTestWithLibs(
+ new String[] {
+ "NullExprTest.java",
+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
+ "import org.eclipse.jdt.annotation.Nullable;\n" +
+ "\n" +
+ "@NonNullByDefault\n" +
+ "public class NullExprTest {\n" +
+ " \n" +
+ " private @Nullable Boolean b() { return null; }\n" +
+ " \n" +
+ " public void testBoolean() {\n" +
+ " Boolean b1 = b();\n" +
+ " boolean b = b1 != null && \n" +
+ " b1; // <-- Previously bugggy: reported potential NPE (*)\n" +
+ " assertTrue(b);\n" +
+ " }\n" +
+ " static void assertTrue(boolean b) {}\n" +
+ "\n" +
+ "}"
+ },
+ getCompilerOptions(),
+ "");
+}
+// negative tests:
+public void testBug422796b() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "NullExprTest.java",
+ "public class NullExprTest {\n" +
+ " \n" +
+ " private Boolean b() { return null; }\n" +
+ " \n" +
+ " public void testBoolean1() {\n" +
+ " Boolean b1 = b();\n" +
+ " boolean b = b1 == null && \n" +
+ " b1; // <-- definite NPE (*)\n" +
+ " assertTrue(b);\n" +
+ " }\n" +
+ " public void testBoolean2(boolean x) {\n" +
+ " Boolean b1 = b();\n" +
+ " boolean b = (b1 == null || x) && \n" +
+ " b1; // <-- potential NPE (*)\n" +
+ " assertTrue(b);\n" +
+ " }\n" +
+ " static void assertTrue(boolean b) {}\n" +
+ "\n" +
+ "}"
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. ERROR in NullExprTest.java (at line 8)\n" +
+ " b1; // <-- definite NPE (*)\n" +
+ " ^^\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
+ "----------\n" +
+ "2. ERROR in NullExprTest.java (at line 14)\n" +
+ " b1; // <-- potential NPE (*)\n" +
+ " ^^\n" +
+ "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
index 6d109319cb..33aae2bd12 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
@@ -11,6 +11,7 @@
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields
* bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
+ * Bug 422796 - [compiler][null] boxed boolean reported as potentially null after null test in lazy disjunction
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -69,7 +70,7 @@ public class AND_AND_Expression extends BinaryExpression {
if ((flowContext.tagBits & FlowContext.INSIDE_NEGATION) != 0)
flowContext.expireNullCheckedFieldInfo();
this.left.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
- this.right.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
+ this.right.checkNPEbyUnboxing(currentScope, flowContext, leftInfo.initsWhenTrue());
FlowInfo mergedInfo = FlowInfo.conditional(
rightInfo.safeInitsWhenTrue(),
leftInfo.initsWhenFalse().unconditionalInits().mergedWith(
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java
index 5e81242910..7c2ea396f3 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java
@@ -12,6 +12,7 @@
* bug 383368 - [compiler][null] syntactic null analysis for field references
* bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields
* bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
+ * Bug 422796 - [compiler][null] boxed boolean reported as potentially null after null test in lazy disjunction
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -74,7 +75,7 @@ public class OR_OR_Expression extends BinaryExpression {
if ((flowContext.tagBits & FlowContext.INSIDE_NEGATION) == 0)
flowContext.expireNullCheckedFieldInfo();
this.left.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
- this.right.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
+ this.right.checkNPEbyUnboxing(currentScope, flowContext, leftInfo.initsWhenFalse());
// The definitely null variables in right info when true should not be missed out while merging
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
FlowInfo leftInfoWhenTrueForMerging = leftInfo.initsWhenTrue().unconditionalCopy().addPotentialInitializationsFrom(rightInfo.unconditionalInitsWithoutSideEffect());

Back to the top