Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-01-22 15:38:35 +0000
committerStephan Herrmann2019-01-22 15:38:35 +0000
commit51aa969ecc1d0045248f76561f2d92330fc6bc27 (patch)
treea83fb411f2cae20f6f3ab8c4bbfa309e570914e3
parentd83eba27c249065f8a479d0ede7680609556ea71 (diff)
downloadeclipse.jdt.core-51aa969ecc1d0045248f76561f2d92330fc6bc27.tar.gz
eclipse.jdt.core-51aa969ecc1d0045248f76561f2d92330fc6bc27.tar.xz
eclipse.jdt.core-51aa969ecc1d0045248f76561f2d92330fc6bc27.zip
Bug 543304 - @NonNull produces an error with arrays of primitivesI20190122-1800
Change-Id: I89a4b5559edbb86cce5f77500587acc5e57bc76e Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java40
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java4
2 files changed, 43 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java
index c483da872e..d6777cb46d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java
@@ -963,4 +963,44 @@ public class NullAnnotationModelTests extends ReconcilerTests {
deleteProject(project);
}
}
+ public void testBug543304() throws Exception {
+ IJavaProject annotations = createJavaProject("Annotations", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
+ IJavaProject client = createJavaProject("Client", new String[] {"src"}, new String[] {"JCL17_LIB"}, "bin", "1.7");
+ try {
+ createFolder("Annotations/src/p");
+ createFile("Annotations/src/p/NonNull.java",
+ "package p;\n" +
+ "import java.lang.annotation.*;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "@Target({METHOD, PARAMETER, FIELD, TYPE_USE})\n" +
+ "public @interface NonNull {}\n");
+ createFile("Annotations/src/p/Nullable.java",
+ "package p;\n" +
+ "import java.lang.annotation.*;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "@Target({METHOD, PARAMETER, FIELD, TYPE_USE})\n" +
+ "public @interface Nullable {}\n");
+
+ addClasspathEntry(client, JavaCore.newProjectEntry(annotations.getPath()));
+ client.setOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "p.NonNull");
+ client.setOption(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "p.Nullable");
+ client.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
+
+ createFile("Client/src/Test.java",
+ "import p.*;\n" +
+ "public class Test {\n" +
+ " @Nullable int[] ints = null;\n" +
+ " public @NonNull Object foo(@NonNull byte[] data) {\n" +
+ " return data;\n" +
+ " }\n" +
+ "}\n");
+
+ getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
+ IMarker[] markers = client.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
+ assertMarkers("Unexpected markers", "", markers);
+ } finally {
+ deleteProject(annotations);
+ deleteProject(client);
+ }
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
index 6e084b3634..393c864722 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -465,6 +465,8 @@ void cachePartsFrom(IBinaryType binaryType, boolean needFieldsAndMethods) {
}
char[] typeSignature = binaryType.getGenericSignature(); // use generic signature even in 1.4
this.tagBits |= binaryType.getTagBits();
+ if (this.environment.globalOptions.complianceLevel < ClassFileConstants.JDK1_8)
+ this.tagBits &= ~TagBits.AnnotationForTypeUse; // avoid confusion with semantics that are not supported at 1.7-
char[][][] missingTypeNames = binaryType.getMissingTypeNames();
SignatureWrapper wrapper = null;

Back to the top