aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2012-07-27 13:41:12 (EDT)
committerStephan Herrmann2012-07-27 13:41:12 (EDT)
commit283b787b0299e1b65451578a582b107860933cd9 (patch)
treebcdb8f9e0cfc8a694c899f414672735175a7ed07
parent582bc933207dd5993c4f5677036ca6833f164aa2 (diff)
downloadeclipse.jdt.core-283b787b0299e1b65451578a582b107860933cd9.zip
eclipse.jdt.core-283b787b0299e1b65451578a582b107860933cd9.tar.gz
eclipse.jdt.core-283b787b0299e1b65451578a582b107860933cd9.tar.bz2
Fixed bug 385626 - @NonNull fails across loop boundariesrefs/changes/04/7004/1
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java56
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java6
3 files changed, 69 insertions, 6 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 253c543..38adde2 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
@@ -53,7 +53,7 @@ public NullAnnotationTest(String name) {
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which do not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "testBug374129" };
+// TESTS_NAMES = new String[] { "testBug385626" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
@@ -3661,4 +3661,58 @@ public void testBug374129() {
libs,
true /* shouldFlush*/);
}
+
+// Bug 385626 - @NonNull fails across loop boundaries
+public void testBug385626_1() {
+ runConformTestWithLibs(
+ new String[] {
+ "X.java",
+ "import java.util.ArrayList;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void test() {\n" +
+ " for (Integer i : new ArrayList<Integer>()) {\n" +
+ " if (i != null) {\n" +
+ " for (Integer j : new ArrayList<Integer>()) {\n" +
+ " if (j != null) {\n" +
+ " @NonNull Integer j1 = i; // bogus error was here\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ null,//options
+ "");
+}
+
+// Bug 385626 - @NonNull fails across loop boundaries
+public void testBug385626_2() {
+ runConformTestWithLibs(
+ new String[] {
+ "X.java",
+ "import java.util.ArrayList;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void test(Integer j) {\n" +
+ " for (Integer i : new ArrayList<Integer>()) {\n" +
+ " if (i != null) {\n" +
+ " try {\n" +
+ " if (j != null) {\n" +
+ " @NonNull Integer j1 = i;\n" +
+ " }\n" +
+ " } finally {\n" +
+ " if (j != null) {\n" +
+ " @NonNull Integer j1 = i; // bogus error was here\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ null,//options
+ "");
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java
index 5e7ad10..7bbb894 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java
@@ -12,6 +12,7 @@
* bug 365519 - editorial cleanup after bug 186342 and bug 365387
* bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK
* bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
+ * bug 385626 - @NonNull fails across loop boundaries
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.flow;
@@ -92,12 +93,16 @@ public void complainOnDeferredChecks(FlowInfo flowInfo, BlockScope scope) {
// check inconsistent null checks
if ((this.tagBits & FlowContext.DEFER_NULL_DIAGNOSTIC) != 0) { // within an enclosing loop, be conservative
for (int i = 0; i < this.nullCount; i++) {
- if ((this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == ASSIGN_TO_NONNULL)
- this.parent.recordNullityMismatch(scope, (Expression)this.nullReferences[i],
- this.providedExpectedTypes[i][0], this.providedExpectedTypes[i][1], flowInfo.nullStatus(this.nullLocals[i]));
- else
+ if ((this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == ASSIGN_TO_NONNULL) {
+ int nullStatus = flowInfo.nullStatus(this.nullLocals[i]);
+ if (nullStatus != FlowInfo.NON_NULL) {
+ this.parent.recordNullityMismatch(scope, (Expression)this.nullReferences[i],
+ this.providedExpectedTypes[i][0], this.providedExpectedTypes[i][1], nullStatus);
+ }
+ } else {
this.parent.recordUsingNullReference(scope, this.nullLocals[i],
this.nullReferences[i], this.nullCheckTypes[i], flowInfo);
+ }
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java
index a15b17c..2ac8981 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java
@@ -13,6 +13,7 @@
* bug 365519 - editorial cleanup after bug 186342 and bug 365387
* bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK
* bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
+ * bug 385626 - @NonNull fails across loop boundaries
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.flow;
@@ -251,7 +252,10 @@ public void complainOnDeferredNullChecks(BlockScope scope, FlowInfo callerFlowIn
}
break;
case ASSIGN_TO_NONNULL:
- this.parent.recordNullityMismatch(scope, (Expression)location, this.providedExpectedTypes[i][0], this.providedExpectedTypes[i][1], flowInfo.nullStatus(local));
+ int nullStatus = flowInfo.nullStatus(local);
+ if (nullStatus != FlowInfo.NON_NULL) {
+ this.parent.recordNullityMismatch(scope, (Expression)location, this.providedExpectedTypes[i][0], this.providedExpectedTypes[i][1], nullStatus);
+ }
break;
case EXIT_RESOURCE:
FakedTrackingVariable trackingVar = local.closeTracker;