Bug 501598 - [null][1.8] Missing warning about redundant nullness
annotation
Change-Id: I406ff1e043fd23ff06f573c20b65b100465aa680
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 2c265aa..d0b68d8 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
@@ -13458,4 +13458,30 @@
""
);
}
+public void testBug501598() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "Foo.java",
+ "import java.util.List;\n" +
+ "\n" +
+ "import org.eclipse.jdt.annotation.NonNull;\n" +
+ "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
+ "\n" +
+ "@NonNullByDefault\n" +
+ "class Foo {\n" +
+ " static <T> @NonNull List<?> f() {\n" +
+ " throw new Error();\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. WARNING in Foo.java (at line 8)\n" +
+ " static <T> @NonNull List<?> f() {\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "The nullness annotation is redundant with a default that applies to this location\n" +
+ "----------\n"
+ );
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java
index 7b4799b..4de0c4a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -194,7 +194,8 @@
Annotation[] innerAnnotations = this.annotationsOnDimensions[0];
return containsNullAnnotation(innerAnnotations);
}
- break;
+ // e.g. subclass ParameterizedSingleTypeReference is not only used for arrays
+ return super.hasNullTypeAnnotation(position);
case ANY:
if (super.hasNullTypeAnnotation(position))
return true;