Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-05-21 17:49:59 +0000
committerJayaprakash Arthanareeswaran2014-05-21 17:49:59 +0000
commitb3e17a909a1b31bd9a62f4bc41b8e8da13b23038 (patch)
tree4b325d1ab0ae064ba5028dafb64a04cebdccbdf9
parent56cd7be7209c3b63ac72922c3a342e501721fcf5 (diff)
downloadeclipse.jdt.core-b3e17a909a1b31bd9a62f4bc41b8e8da13b23038.tar.gz
eclipse.jdt.core-b3e17a909a1b31bd9a62f4bc41b8e8da13b23038.tar.xz
eclipse.jdt.core-b3e17a909a1b31bd9a62f4bc41b8e8da13b23038.zip
Bug 434899 - [1.8][null] Java 1.8 null annotations still cause
Contradictory null annotations' error Signed-off-by: stephan.herrmann@berlin.de
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java45
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java4
2 files changed, 49 insertions, 0 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 5be1265c56..12da2b2e50 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
@@ -5227,4 +5227,49 @@ public void testBug433478() {
"Null type mismatch: required \'@NonNull Y\' but the provided value is null\n" +
"----------\n");
}
+// https://bugs.eclipse.org/434899
+public void testTypeVariable6() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "Assert.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class Assert {\n" +
+ " public static void caller() {\n" +
+ " assertNotNull(\"not null\"); // Compiler error\n" +
+ " assertNotNull(null); // Compiler error\n" +
+ " }\n" +
+ " private static @NonNull <T> T assertNotNull(@Nullable T object) {\n" +
+ " return object; // this IS bogus\n" +
+ " }\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "----------\n" +
+ "1. ERROR in Assert.java (at line 8)\n" +
+ " return object; // this IS bogus\n" +
+ " ^^^^^^\n" +
+ "Null type mismatch (type annotations): required \'@NonNull T\' but this expression has type \'@Nullable T\'\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/434899 - variant which has always worked
+public void testTypeVariable6a() {
+ runConformTestWithLibs(
+ new String[] {
+ "Assert.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class Assert {\n" +
+ " public static Object caller() {\n" +
+ " @NonNull Object result = assertNotNull(\"not null\");\n" +
+ " result = assertNotNull(null);\n" +
+ " return result;\n" +
+ " }\n" +
+ " private static @NonNull <T> T assertNotNull(@Nullable T object) {\n" +
+ " if (object == null) throw new NullPointerException();\n" +
+ " return object;\n" +
+ " }\n" +
+ "}\n"
+ },
+ getCompilerOptions(),
+ "");
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
index 2e6f8aa7c6..b28f02423e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
@@ -373,6 +373,10 @@ public class InferenceContext18 {
public BoundSet inferInvocationType(BoundSet b1, TypeBinding expectedType, InvocationSite invocationSite, MethodBinding method)
throws InferenceFailureException
{
+ // not JLS: simply ensure that null hints from the return type have been seen even in standalone contexts:
+ if (expectedType == null && method.returnType != null)
+ substitute(method.returnType); // result is ignore, the only effect is on InferenceVariable.nullHints
+ //
BoundSet previous = this.currentBounds.copy();
this.currentBounds = b1;
try {

Back to the top