Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-07-20 20:22:06 +0000
committerStephan Herrmann2014-07-22 13:03:24 +0000
commit403deed13ad4115ce80e0449d5be70cb085b39a1 (patch)
tree1a5125fea2afb531cb431f2ea254fb873261fc31
parent68b132a771077222c8a489923225ada23ba86a6a (diff)
downloadeclipse.jdt.core-403deed13ad4115ce80e0449d5be70cb085b39a1.tar.gz
eclipse.jdt.core-403deed13ad4115ce80e0449d5be70cb085b39a1.tar.xz
eclipse.jdt.core-403deed13ad4115ce80e0449d5be70cb085b39a1.zip
Bug 438250 - [1.8][null] NPE trying to report bogus null annotation
conflict
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java27
2 files changed, 30 insertions, 10 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 383add0bc7..2d39a09709 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
@@ -5464,6 +5464,19 @@ public void testTypeVariable11() {
"The explicit type bound \'Object\' is not affected by the nullness default for DefaultLocation.TYPE_BOUND.\n" +
"----------\n");
}
+// Bug 438250 - [1.8][null] NPE trying to report bogus null annotation conflict
+public void testTypeVariable13() {
+ runConformTestWithLibs(
+ new String[] {
+ "FooBar.java",
+ "@org.eclipse.jdt.annotation.NonNullByDefault(org.eclipse.jdt.annotation.DefaultLocation.TYPE_BOUND)\n" +
+ "public interface FooBar {\n" +
+ " <@org.eclipse.jdt.annotation.Nullable R extends Runnable> R foobar(R r);\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "");
+}
public void testBug434600() {
runConformTestWithLibs(
new String[] {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java
index f495387a6f..02eeab0fe9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java
@@ -24,6 +24,7 @@
* Bug 431408 - Java 8 (1.8) generics bug
* Bug 435962 - [RC2] StackOverFlowError when building
* Bug 438458 - [1.8][null] clean up handling of null type annotations wrt type variables
+ * Bug 438250 - [1.8][null] NPE trying to report bogus null annotation conflict
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -806,11 +807,7 @@ public class TypeVariableBinding extends ReferenceBinding {
if (nullTagBits == 0L) {
nullTagBits |= superNullTagBits;
} else if (superNullTagBits != nullTagBits) {
- // not finding either bound or ann should be considered a compiler bug
- TypeReference bound = findBound(this.firstBound, parameter);
- Annotation ann = bound.findAnnotation(superNullTagBits);
- scope.problemReporter().contradictoryNullAnnotationsOnBounds(ann, nullTagBits);
- this.tagBits &= ~TagBits.AnnotationNullMASK;
+ this.firstBound = nullMismatchOnBound(parameter, this.firstBound, superNullTagBits, nullTagBits, scope);
}
}
}
@@ -824,11 +821,7 @@ public class TypeVariableBinding extends ReferenceBinding {
if (nullTagBits == 0L) {
nullTagBits |= superNullTagBits;
} else if (superNullTagBits != nullTagBits) {
- // not finding either bound or ann should be considered a compiler bug
- TypeReference bound = findBound(this.firstBound, parameter);
- Annotation ann = bound.findAnnotation(superNullTagBits);
- scope.problemReporter().contradictoryNullAnnotationsOnBounds(ann, nullTagBits);
- this.tagBits &= ~TagBits.AnnotationNullMASK;
+ interfaces[i] = (ReferenceBinding) nullMismatchOnBound(parameter, resolveType, superNullTagBits, nullTagBits, scope);
}
}
interfaces[i] = resolveType;
@@ -837,6 +830,20 @@ public class TypeVariableBinding extends ReferenceBinding {
if (nullTagBits != 0)
this.tagBits |= nullTagBits | TagBits.HasNullTypeAnnotation;
}
+ private TypeBinding nullMismatchOnBound(TypeParameter parameter, TypeBinding boundType, long superNullTagBits, long nullTagBits, Scope scope) {
+ // not finding bound should be considered a compiler bug
+ TypeReference bound = findBound(boundType, parameter);
+ Annotation ann = bound.findAnnotation(superNullTagBits);
+ if (ann != null) {
+ // explicit annotation: error
+ scope.problemReporter().contradictoryNullAnnotationsOnBounds(ann, nullTagBits);
+ this.tagBits &= ~TagBits.AnnotationNullMASK;
+ } else {
+ // implicit annotation: let the new one override
+ return boundType.unannotated(true);
+ }
+ return boundType;
+ }
private TypeReference findBound(TypeBinding bound, TypeParameter parameter) {
if (parameter.type != null && TypeBinding.equalsEquals(parameter.type.resolvedType, bound))
return parameter.type;

Back to the top