diff options
author | Stephan Herrmann | 2020-02-18 15:01:27 +0000 |
---|---|---|
committer | Stephan Herrmann | 2020-02-18 15:01:27 +0000 |
commit | 4ce8fc36a787f1398903447a1816ff5fb4392149 (patch) | |
tree | 253bc76d56577afb59d2adc53a950c9c89e50c72 | |
parent | 1a930ae92c069b627b521736fa49ab1dc3794efb (diff) | |
download | eclipse.jdt.core-4ce8fc36a787f1398903447a1816ff5fb4392149.tar.gz eclipse.jdt.core-4ce8fc36a787f1398903447a1816ff5fb4392149.tar.xz eclipse.jdt.core-4ce8fc36a787f1398903447a1816ff5fb4392149.zip |
Bug 560213 - [null] Bogus warning about @NonNullByDefault enum whenX20200223-1900X20200223-0700X20200223-0250X20200222-0700X20200221-1130X20200221-0700X20200221-0440X20200221-0310X20200221-0050X20200220-1900X20200220-0700X20200219-1900X20200219-0700X20200219-0500S4_15_0_M3I20200223-1800I20200223-0600I20200222-1800I20200222-0600I20200221-1800I20200219-1800I20200219-0600I20200218-1800
accessed as BTB
- avoid the new problem in this situation for now
Change-Id: I32f46cf43d3e06336bcddcf79a9a8a46af384706
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; |