diff options
2 files changed, 70 insertions, 2 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 66d6ea278a..a89da8868d 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 @@ -17995,4 +17995,71 @@ public void testBug482242_boundedWildcard() { "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'capture#of ? super @Nullable String\'\n" + "----------\n"); } +public void testBug560213source() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "nullEnumSort/MyEnum.java", + "package nullEnumSort;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "enum MyEnum {\n" + + " x\n" + + "}\n", + "nullEnumSort/EnumProblem.java", + "package nullEnumSort;\n" + + "\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class EnumProblem {\n" + + " void f(List<MyEnum> list) {\n" + + " Collections.sort(list);\n" + + " }\n" + + "\n}" + }; + runner.runConformTest(); +} +public void testBug560213binary() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.testFiles = new String[] { + "nullEnumSort/MyEnum.java", + "package nullEnumSort;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "enum MyEnum {\n" + + " x\n" + + "}\n" + }; + runner.classLibraries = this.LIBS; + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = new String[] { + "nullEnumSort/EnumProblem.java", + "package nullEnumSort;\n" + + "\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class EnumProblem {\n" + + " void f(List<MyEnum> list) {\n" + + " Collections.sort(list);\n" + + " }\n" + + "\n}" + }; + runner.runConformTest(); +} } 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 bb3ca2a0b7..9a3eadafc8 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -295,7 +295,8 @@ public class TypeVariableBinding extends ReferenceBinding { } private BoundCheckStatus nullBoundCheck(Scope scope, TypeBinding argumentType, TypeBinding substitutedSuperType, Substitution substitution, ASTNode location, BoundCheckStatus previousStatus) { - if (NullAnnotationMatching.analyse(this, argumentType, substitutedSuperType, substitution, -1, null, CheckMode.BOUND_CHECK).isAnyMismatch()) { + NullAnnotationMatching status = NullAnnotationMatching.analyse(this, argumentType, substitutedSuperType, substitution, -1, null, CheckMode.BOUND_CHECK); + if (status.isAnyMismatch() && !status.isAnnotatedToUnannotated()) { if (location != null) scope.problemReporter().nullityMismatchTypeArgument(this, argumentType, location); return BoundCheckStatus.NULL_PROBLEM; |