Bug 560213 - [null] Bogus warning about @NonNullByDefault enum when
accessed as BTB

- avoid the new problem in this situation for now

Change-Id: I32f46cf43d3e06336bcddcf79a9a8a46af384706
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 66d6ea2..a89da88 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 @@
 		"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 bb3ca2a..9a3eada 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 @@
 	}
 
 	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;