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 45b209a..06438b1 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 @@ -486,7 +486,7 @@ "Type mismatch: required \'@NonNull Object\' but the provided value is null\n" + "----------\n" /* compiler output */); } -//null is passed to a non-null parameter in a qualified allocation expression, generic constructor, target class read from .class +// null is passed to a non-null parameter in a qualified allocation expression, generic constructor, target class read from .class public void test_nonnull_parameter_012() { Map customOptions = getCompilerOptions(); customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_INSUFFICIENT_INFO, JavaCore.ERROR); @@ -2390,4 +2390,36 @@ }, ""); } +// test analysis disablement, binary type contains annotation +public void test_disabled_1() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_INSUFFICIENT_INFO, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "ContainingInner2.java", + "public class ContainingInner2 {\n" + + " public ContainingInner2 (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " public class Inner {\n" + + " public Inner (@org.eclipse.jdt.annotation.NonNull T o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + null /*customOptions*/, + ""); + customOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.DISABLED); + runConformTestWithLibs( + false, // flush directory + new String[] { + "X.java", + "public class X {\n" + + " void create() {\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " }\n" + + "}\n"}, + customOptions, + "" /* compiler output */); +} } 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 63d5fcb..b2240c1 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 @@ -1152,10 +1152,12 @@ return this.storedAnnotations; } void scanMethodForNullAnnotation(IBinaryMethod method, MethodBinding methodBinding) { + if (!this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) + return; char[][] nullableAnnotationName = this.environment.getNullableAnnotationName(); char[][] nonNullAnnotationName = this.environment.getNonNullAnnotationName(); if (nullableAnnotationName == null || nonNullAnnotationName == null) - return; // not configured to use null annotations + return; // not well-configured to use null annotations // return: IBinaryAnnotation[] annotations = method.getAnnotations(); @@ -1204,9 +1206,11 @@ } } void scanTypeForNullAnnotation(IBinaryType binaryType) { + if (!this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) + return; char[][] nonNullByDefaultAnnotationName = this.environment.getNonNullByDefaultAnnotationName(); if (nonNullByDefaultAnnotationName == null) - return; // not configured to use null annotations + return; // not well-configured to use null annotations IBinaryAnnotation[] annotations = binaryType.getAnnotations(); if (annotations != null) {