Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-07-20 09:15:50 +0000
committerStephan Herrmann2014-07-22 13:03:15 +0000
commiteba39b7d16632d43ea13707b696b73d1b911dc13 (patch)
tree07d90f177ad95eb06ba9e719f6e30f4196f1189e
parent63231f253dc3aaae18caf57a7f77da85f8cefe96 (diff)
downloadeclipse.jdt.core-eba39b7d16632d43ea13707b696b73d1b911dc13.tar.gz
eclipse.jdt.core-eba39b7d16632d43ea13707b696b73d1b911dc13.tar.xz
eclipse.jdt.core-eba39b7d16632d43ea13707b696b73d1b911dc13.zip
Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit
type bound of binary type - warning for explicit "<T extends Object>"
-rw-r--r--org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation/DefaultLocation.java4
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java3
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java26
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties2
7 files changed, 55 insertions, 5 deletions
diff --git a/org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation/DefaultLocation.java b/org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation/DefaultLocation.java
index 5d78d541f3..02677bfc38 100644
--- a/org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation/DefaultLocation.java
+++ b/org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation/DefaultLocation.java
@@ -80,7 +80,9 @@ public enum DefaultLocation {
/**
* Defines that a given {@link NonNullByDefault} annotation should affect all unannotated
- * explicit type bounds within the scope of the annotated declaration.
+ * explicit type bounds within the scope of the annotated declaration. A type bound of
+ * type {@link java.lang.Object} is <strong>never</strong> considered as an explicit bound,
+ * i.e., <code>T extends Object</code> is never affected by {@link NonNullByDefault}.
*
* <h2>Example</h2>
* <pre> @NonNullByDefault(TYPE_BOUND)
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 5ab2e5c862..1a8ca337a0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -33,6 +33,7 @@
* Bug 424637 - [1.8][compiler][null] AIOOB in ReferenceExpression.resolveType with a method reference to Files::walk
* Bug 418743 - [1.8][null] contradictory annotations on invocation of generic method not reported
* Bug 430150 - [1.8][null] stricter checking against type variables
+ * Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type
* Jesper S Moller - Contributions for
* bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression
* bug 382721 - [1.8][compiler] Effectively final variables needs special treatment
@@ -592,6 +593,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IllegalVisibilityModifierForInterfaceMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+ expectedProblemAttributes.put("ImplicitObjectBoundNoNullDefault", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("ImportAmbiguous", DEPRECATED);
expectedProblemAttributes.put("ImportInheritedNameHidesEnclosingName", DEPRECATED);
expectedProblemAttributes.put("ImportInternalNameProvided", DEPRECATED);
@@ -1413,6 +1415,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMemberType", SKIP);
expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMethod", SKIP);
expectedProblemAttributes.put("IllegalVisibilityModifierForInterfaceMemberType", SKIP);
+ expectedProblemAttributes.put("ImplicitObjectBoundNoNullDefault", SKIP);
expectedProblemAttributes.put("ImportAmbiguous", SKIP);
expectedProblemAttributes.put("ImportInheritedNameHidesEnclosingName", SKIP);
expectedProblemAttributes.put("ImportInternalNameProvided", SKIP);
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 ae505e794e..4b92fecdaa 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
@@ -5408,6 +5408,32 @@ public void testTypeVariable10() {
getCompilerOptions(),
"");
}
+// Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type
+// warning for explicit "<T extends Object>"
+public void testTypeVariable11() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.DefaultLocation;\n" +
+ "@org.eclipse.jdt.annotation.NonNullByDefault({DefaultLocation.TYPE_BOUND})\n" + // not: PARAMETER
+ "public class X<T extends Object> {\n" +
+ " void test(T t) {}\n" +
+ "}\n",
+ "Y.java",
+ "public class Y {\n" +
+ " void foo(X<@org.eclipse.jdt.annotation.Nullable String> xs) {\n" +
+ " xs.test(null);\n" +
+ " }\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " public class X<T extends Object> {\n" +
+ " ^^^^^^\n" +
+ "The explicit type bound \'Object\' is not affected by the nullness default for DefaultLocation.TYPE_BOUND.\n" +
+ "----------\n");
+}
public void testBug434600() {
runConformTestWithLibs(
new String[] {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index b84e5e4435..6f5d0b4251 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -192,6 +192,7 @@
* NonNullDefaultDetailIsNotEvaluated
* NullNotCompatibleToFreeTypeVariable
* NullityMismatchAgainstFreeTypeVariable
+ * ImplicitObjectBoundNoNullDefault
* Jesper S Moller - added the following constants
* TargetTypeNotAFunctionalInterface
* OuterLocalMustBeEffectivelyFinal
@@ -1790,6 +1791,9 @@ void setSourceStart(int sourceStart);
int NullNotCompatibleToFreeTypeVariable = 969;
/** @since 3.10 */
int NullityMismatchAgainstFreeTypeVariable = 970;
+ /** @since 3.11 */
+ int ImplicitObjectBoundNoNullDefault = 971;
+
// Java 8 work
/** @since 3.10 */
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java
index d2acbf5cef..4dfada6ed4 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java
@@ -18,6 +18,7 @@
* Bug 429958 - [1.8][null] evaluate new DefaultLocation attribute of @NonNullByDefault
* Bug 434570 - Generic type mismatch for parametrized class annotation attribute with inner class
* Bug 434600 - Incorrect null analysis error reporting on type parameters
+ * Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
* Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
@@ -631,12 +632,16 @@ protected void resolveAnnotations(Scope scope, int location) {
&& (this.resolvedType.tagBits & TagBits.AnnotationNullMASK) == 0
&& !this.resolvedType.isTypeVariable()
&& !this.resolvedType.isWildcard()
- && location != 0
+ && location != 0
&& scope.hasDefaultNullnessFor(location))
{
- LookupEnvironment environment = scope.environment();
- AnnotationBinding[] annots = new AnnotationBinding[]{environment.getNonNullAnnotation()};
- this.resolvedType = environment.createAnnotatedType(this.resolvedType, annots);
+ if (location == Binding.DefaultLocationTypeBound && this.resolvedType.id == TypeIds.T_JavaLangObject) {
+ scope.problemReporter().implicitObjectBoundNoNullDefault(this);
+ } else {
+ LookupEnvironment environment = scope.environment();
+ AnnotationBinding[] annots = new AnnotationBinding[]{environment.getNonNullAnnotation()};
+ this.resolvedType = environment.createAnnotatedType(this.resolvedType, annots);
+ }
}
}
public int getAnnotatableLevels() {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index b948b9119b..a40eb685f8 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -50,6 +50,7 @@
* Bug 390889 - [1.8][compiler] Evaluate options to support 1.7- projects against 1.8 JRE.
* Bug 430150 - [1.8][null] stricter checking against type variables
* Bug 434600 - Incorrect null analysis error reporting on type parameters
+ * Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type
* Jesper S Moller <jesper@selskabet.org> - Contributions for
* bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression
* bug 382721 - [1.8][compiler] Effectively final variables needs special treatment
@@ -9789,6 +9790,13 @@ public void nullityMismatchTypeArgument(TypeBinding typeVariable, TypeBinding ty
location.sourceEnd);
}
+public void implicitObjectBoundNoNullDefault(TypeReference reference) {
+ this.handle(IProblem.ImplicitObjectBoundNoNullDefault,
+ NoArgument, NoArgument,
+ ProblemSeverities.Warning,
+ reference.sourceStart, reference.sourceEnd);
+}
+
public void dereferencingNullableExpression(Expression expression) {
if (expression instanceof MessageSend) {
MessageSend send = (MessageSend) expression;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 9bb1d16144..2f6d243592 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -39,6 +39,7 @@
# Bug 392245 - [1.8][compiler][null] Define whether / how @NonNullByDefault applies to TYPE_USE locations
# Bug 430150 - [1.8][null] stricter checking against type variables
# Bug 434600 - Incorrect null analysis error reporting on type parameters
+# Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type
# Jesper S Moller <jesper@selskabet.org> - Contributions for
# bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression
# bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration
@@ -823,6 +824,7 @@
#968 temporary warning has been removed
969 = Null type mismatch (type annotations): ''null'' is not compatible to the free type variable ''{0}''
970 = Null type mismatch (type annotations): required ''{0}'' but this expression has type ''{1}'', where ''{0}'' is a free type variable
+971 = The explicit type bound 'Object' is not affected by the nullness default for DefaultLocation.TYPE_BOUND.
# Java 8
1001 = Syntax error, modifiers and annotations are not allowed for the lambda parameter {0} as its type is elided

Back to the top