Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-03-08 17:31:38 +0000
committerStephan Herrmann2014-03-08 17:31:38 +0000
commit5d6f5aaa0ef90debc42dc50e444944b70d619e1f (patch)
tree0752e4222b654e5c9b5d3ad090067c3d44cb843f
parentb6755ce2d08e0d5d352a051fea787f1496b49482 (diff)
downloadeclipse.jdt.core-5d6f5aaa0ef90debc42dc50e444944b70d619e1f.tar.gz
eclipse.jdt.core-5d6f5aaa0ef90debc42dc50e444944b70d619e1f.tar.xz
eclipse.jdt.core-5d6f5aaa0ef90debc42dc50e444944b70d619e1f.zip
Bug 429403 - [1.8][null] null mismatch from type arguments is not
reported at field initializer
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java22
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java14
2 files changed, 27 insertions, 9 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index 9f60a2a09e..3929201fdb 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -968,7 +968,7 @@ public class NullTypeAnnotationTest extends AbstractNullAnnotationTest {
"import org.eclipse.jdt.annotation.*;\n" +
"public abstract class X1 {\n" +
" public static String @Nullable [] f1 = null;\n" +
- " public static String [] @Nullable [] f2 = new String[][] { null };\n" +
+ " public static String [] @Nullable [] f2 = new String[] @Nullable[] { null };\n" +
"}\n"
},
customOptions,
@@ -1511,7 +1511,7 @@ public class NullTypeAnnotationTest extends AbstractNullAnnotationTest {
"import org.eclipse.jdt.annotation.NonNull;\n" +
"import org.eclipse.jdt.annotation.Nullable;\n" +
"public class X {\n" +
- " @NonNull String @Nullable [] f @NonNull [] = new @NonNull String @Nullable [0] @NonNull [];\n" +
+ " @NonNull String @Nullable [] f @NonNull [] = new @NonNull String @NonNull [0] @Nullable [];\n" +
"}\n"
},
customOptions,
@@ -4303,4 +4303,22 @@ public void test429387() {
"IntStreamy cannot be resolved\n" +
"----------\n");
}
+public void testBug429403() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "class Person {}\n" +
+ "public class X {\n" +
+ " List<@NonNull Person> l = new ArrayList<@Nullable Person>();" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " List<@NonNull Person> l = new ArrayList<@Nullable Person>();}\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Null type mismatch (type annotations): required \'List<@NonNull Person>\' but this expression has type \'ArrayList<@Nullable Person>\', corresponding supertype is \'List<@Nullable Person>\'\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java
index 8b55d6f211..5083fb26fd 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java
@@ -16,6 +16,7 @@
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
* Bug 427438 - [1.8][compiler] NPE at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.generateCode(ConditionalExpression.java:280)
+ * Bug 429403 - [1.8][null] null mismatch from type arguments is not reported at field initializer
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
* Bug 409250 - [1.8][compiler] Various loose ends in 308 code generation
*******************************************************************************/
@@ -92,13 +93,12 @@ public FlowInfo analyseCode(MethodScope initializationScope, FlowContext flowCon
.unconditionalInits();
flowInfo.markAsDefinitelyAssigned(this.binding);
}
- if (this.initialization != null) {
- if (this.binding.isNonNull()) {
- int nullStatus = this.initialization.nullStatus(flowInfo, flowContext);
- // check against annotation @NonNull:
- if (nullStatus != FlowInfo.NON_NULL) {
- char[][] annotationName = initializationScope.environment().getNonNullAnnotationName();
- initializationScope.problemReporter().nullityMismatch(this.initialization, this.initialization.resolvedType, this.binding.type, nullStatus, annotationName);
+ if (this.initialization != null && this.binding != null) {
+ CompilerOptions options = initializationScope.compilerOptions();
+ if (options.isAnnotationBasedNullAnalysisEnabled) {
+ if (this.binding.isNonNull() || options.sourceLevel >= ClassFileConstants.JDK1_8) {
+ int nullStatus = this.initialization.nullStatus(flowInfo, flowContext);
+ NullAnnotationMatching.checkAssignment(initializationScope, flowContext, this.binding, nullStatus, this.initialization, this.initialization.resolvedType);
}
}
this.initialization.checkNPEbyUnboxing(initializationScope, flowContext, flowInfo);

Back to the top