Bug 489245 - [1.8][null][lambda] bogus problem report in lambda block
when severity is set to "info"


Change-Id: I3b2ccf1e51c8ca7a437c40b769584bc3015f871c
Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
index c160673..0a39103 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
@@ -8114,7 +8114,7 @@
 		"Null type safety: The expression of type \'T\' needs unchecked conversion to conform to \'@NonNull T\'\n" + 
 		"----------\n"
 		:
-		"3. WARNING in EclipseBug.java (at line 10)\n" + 
+		"3. INFO in EclipseBug.java (at line 10)\n" + 
 		"	return commandType.newInstance();\n" + 
 		"	       ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
 		"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Class<T extends @NonNull String>\'. Type \'Class<T>\' doesn\'t seem to be designed with null type annotations in mind\n" + 
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 2dadff0..66dc54e 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
@@ -3100,7 +3100,7 @@
 			"	       ^^^^\n" + 

 			"Null type mismatch: required \'@NonNull ? extends @NonNull String\' but the provided value is null\n" + 

 			"----------\n" + 

-			"3. WARNING in X.java (at line 10)\n" + 

+			"3. INFO in X.java (at line 10)\n" + 

 			"	@NonNull String s = ls.get(0);\n" + 

 			"	                    ^^^^^^^^^\n" + 

 			"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<@NonNull capture#of ? extends @NonNull String>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -3426,7 +3426,7 @@
 			},

 			getCompilerOptions(),

 			"----------\n" + 

-			"1. WARNING in X.java (at line 6)\n" + 

+			"1. INFO in X.java (at line 6)\n" + 

 			"	return l.get(0);\n" + 

 			"	       ^^^^^^^^\n" + 

 			"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull List<@NonNull T>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -4435,7 +4435,7 @@
 		"	        ^^^^\n" + 

 		"Null type mismatch: required \'? extends @NonNull A\' but the provided value is null\n" + 

 		"----------\n" + 

-		"2. WARNING in C.java (at line 14)\n" + 

+		"2. INFO in C.java (at line 14)\n" + 

 		"	return la1.get(0); // OK\n" + 

 		"	       ^^^^^^^^^^\n" + 

 		"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<capture#of ? extends @NonNull A>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -4983,7 +4983,7 @@
 		},

 		getCompilerOptions(),

 		"----------\n" + 

-		"1. WARNING in X.java (at line 8)\n" + 

+		"1. INFO in X.java (at line 8)\n" + 

 		"	@NonNull Number n = l.get(0); // OK\n" + 

 		"	                    ^^^^^^^^\n" + 

 		"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<capture#of ? extends @NonNull Number>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -6710,12 +6710,12 @@
 		},

 		getCompilerOptions(),

 		"----------\n" + 

-		"1. WARNING in Foo.java (at line 17)\n" + 

+		"1. INFO in Foo.java (at line 17)\n" + 

 		"	return requireNonNull(foos).get(0);\n" + 

 		"	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 

 		"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull List<capture#of ? extends @NonNull Foo>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

 		"----------\n" + 

-		"2. WARNING in Foo.java (at line 20)\n" + 

+		"2. INFO in Foo.java (at line 20)\n" + 

 		"	return requireNonNull(foos.get(0)).get(0);\n" + 

 		"	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 

 		"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<@NonNull Foo>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -8086,7 +8086,7 @@
     		"	         ^^^^^^^^^^^\n" + 

     		"GenericType is a raw type. References to generic type GenericType<T> should be parameterized\n" + 

     		"----------\n" + 

-    		"2. WARNING in projB\\ClassThatImports.java (at line 7)\n" + 

+    		"2. INFO in projB\\ClassThatImports.java (at line 7)\n" + 

     		"	@NonNull GenericType gt = cwru.method().get(0);\n" + 

     		"	                          ^^^^^^^^^^^^^^^^^^^^\n" + 

     		"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull List<@NonNull GenericType>\'. Type \'List<E>\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -8386,7 +8386,7 @@
 		},

 		compilerOptions,

 		"----------\n" + 

-		"1. WARNING in Test.java (at line 9)\n" + 

+		"1. INFO in Test.java (at line 9)\n" + 

 		"	return Objects.requireNonNull(function.apply(input));\n" + 

 		"	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 

 		"Unsafe interpretation of method return type as \'@NonNull\' based on substitution \'T=@NonNull capture#of ? extends R\'. Declaring type \'Objects\' doesn\'t seem to be designed with null type annotations in mind\n" + 

@@ -12185,4 +12185,45 @@
 		""

 	);

 }

+public void testBug489245() {

+	Map compilerOptions = getCompilerOptions();

+	compilerOptions.put(CompilerOptions.OPTION_PessimisticNullAnalysisForFreeTypeVariables, JavaCore.INFO);

+	runNegativeTestWithLibs(

+		new String[] {

+			"test/TestBogusProblemReportOnlyAsInfo.java",

+			"package test;\n" +

+			"\n" +

+			"import java.util.function.Supplier;\n" +

+			"\n" +

+			"import org.eclipse.jdt.annotation.NonNull;\n" +

+			"import org.eclipse.jdt.annotation.NonNullByDefault;\n" +

+			"\n" +

+			"@NonNullByDefault\n" +

+			"public class TestBogusProblemReportOnlyAsInfo {\n" +

+			"	static <U> void get(Supplier<U> supplier, @NonNull U defaultValue) {\n" +

+			"	}\n" +

+			"\n" +

+			"	static void f() {\n" +

+			"		get(() -> {\n" +

+			"			return null; // bogus problem report only as info\n" +

+			"		}, \"\");\n" +

+			"	}\n" +

+			"\n" +

+			"	static <T> void h(@NonNull T t) {\n" +

+			"		get(() -> {\n" +

+			"			return null; // correctly reported (but twice with the bug)\n" +

+			"		}, t);\n" +

+			"	}\n" +

+			"}\n" +

+			"",

+		}, 

+		compilerOptions,

+		"----------\n" + 

+		"1. INFO in test\\TestBogusProblemReportOnlyAsInfo.java (at line 21)\n" + 

+		"	return null; // correctly reported (but twice with the bug)\n" + 

+		"	       ^^^^\n" + 

+		"Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + 

+		"----------\n"

+	);

+}

 }

diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java
index ce7b35c..c2bcadf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java
@@ -141,7 +141,7 @@
    }
 
 public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) {
-    problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
+    problems.append(problemCount + (problem.isError() ? ". ERROR" : problem.isWarning() ? ". WARNING" : ". INFO"));
     problems.append(" in " + new String(problem.getOriginatingFileName()));
     if (source != null) {
         problems.append(((DefaultProblem)problem).errorReportSource(source));
@@ -1397,7 +1397,7 @@
 				if (problemCount == 0)
 					buffer.append("----------\n");
 				problemCount++;
-				buffer.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
+				buffer.append(problemCount + (problem.isError() ? ". ERROR" : problem.isWarning() ? ". WARNING" : ". INFO"));
 				buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\'));
 				try {
 					buffer.append(problem.errorReportSource(unitSource));
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
index dafe42a..77e8e60 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
@@ -125,7 +125,7 @@
 		return;
 
 	 boolean mandatory = (severity & (ProblemSeverities.Error | ProblemSeverities.Optional)) == ProblemSeverities.Error;
-	 if (severity < ProblemSeverities.InternalError && this.policy.ignoreAllErrors()) { 
+	 if ((severity & ProblemSeverities.InternalError) == 0 && this.policy.ignoreAllErrors()) { 
 		 // Error is not to be exposed, but clients may need still notification as to whether there are silently-ignored-errors.
 		 // if no reference context, we need to abort from the current compilation process
 		 if (referenceContext == null) {