Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2020-01-05 18:24:53 +0000
committerStephan Herrmann2020-01-05 20:10:42 +0000
commit256ddbc372ca0b473cf9e1359cd51a98fe2f20d9 (patch)
treebf15d12b998c29676366410d685141d65ed7af43
parentaf36a4d61d16ed2e7dc7a2bcd257172b51335524 (diff)
downloadeclipse.jdt.core-256ddbc372ca0b473cf9e1359cd51a98fe2f20d9.tar.gz
eclipse.jdt.core-256ddbc372ca0b473cf9e1359cd51a98fe2f20d9.tar.xz
eclipse.jdt.core-256ddbc372ca0b473cf9e1359cd51a98fe2f20d9.zip
Bug 479389 - [null] warn when annotation based null analysis is enabledI20200106-0600I20200105-1800
but null annotations are not on the classpath - revert problem configurability Change-Id: Ide1060799976eee38b103fcd798f68252a3838f7
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java3
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java51
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java17
7 files changed, 13 insertions, 83 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 39be38bd97..4bb46891c0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -1064,8 +1064,7 @@ public void test012b(){
" <option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTags\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding\" value=\"disabled\"/>\n" +
- " <option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility\" value=\"public\"/>\n" +
- " <option key=\"org.eclipse.jdt.core.compiler.problem.missingNullAnnotationImplicitlyUsed\" value=\"error\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility\" value=\"public\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation\" value=\"enabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.missingSerialVersion\" value=\"warning\"/>\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 57d402320a..7e4e8c3434 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -1795,7 +1795,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("MissingEnumDefaultCase", new ProblemAttributes(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE));
expectedProblemAttributes.put("MissingNonNullByDefaultAnnotationOnPackage", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION));
expectedProblemAttributes.put("MissingNonNullByDefaultAnnotationOnType", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION));
- expectedProblemAttributes.put("MissingNullAnnotationImplicitlyUsed", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_NULL_ANNOTATION_IMPLICITLY_USED));
+ expectedProblemAttributes.put("MissingNullAnnotationImplicitlyUsed", SKIP);
expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION));
expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION));
expectedProblemAttributes.put("MissingRequiresTransitiveForTypeInAPI", new ProblemAttributes(JavaCore.COMPILER_PB_API_LEAKS));
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 735c3bf727..0cf01c8e5e 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
@@ -1096,7 +1096,7 @@ public class NullAnnotationModelTests extends ReconcilerTests {
}
public void testBug479389() throws CoreException, IOException {
IJavaProject project = null;
- try {
+ try {
project = createJavaProject("Bug479389", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
project.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
@@ -1132,51 +1132,8 @@ public class NullAnnotationModelTests extends ReconcilerTests {
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Annotation type \'org.eclipse.jdt.annotation.NonNull\' cannot be found on the build path, which is implicitly needed for null analysis\n" +
"----------\n" );
- } finally {
- deleteProject(project);
- }
- }
- public void testBug479389_warning() throws CoreException, IOException {
- IJavaProject project = null;
- try {
- project = createJavaProject("Bug479389", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
- project.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
- project.setOption(JavaCore.COMPILER_PB_MISSING_NULL_ANNOTATION_IMPLICITLY_USED, JavaCore.WARNING);
-
- createFolder("Bug479389/src/nullAnalysis");
- String testSource =
- "package nullAnalysis;\n" +
- "interface MyList<T> {\n" +
- " public Stream<T> stream();\n" +
- "}\n" +
- "interface Stream<T> {\n" +
- " T[] toArray(IntFunction<T[]> supplier);" +
- "}\n" +
- "interface IntFunction<T> {\n" +
- " T apply(int i);\n" +
- "}\n" +
- "public class X {\n" +
- "\n" +
- " public String[] method(MyList<String> in) {\n" +
- " return in.stream().toArray(String[]::new);\n" +
- " }\n" +
- "}\n";
- String testSourcePath = "Bug479389/src/nullAnalysis/X.java";
- createFile(testSourcePath, testSource);
- char[] testSourceChars = testSource.toCharArray();
- this.problemRequestor.initialize(testSourceChars);
-
- getCompilationUnit(testSourcePath).getWorkingCopy(this.wcOwner, null);
- assertProblems(
- "Unexpected problems",
- "----------\n" +
- "1. WARNING in /Bug479389/src/nullAnalysis/X.java (at line 13)\n" +
- " return in.stream().toArray(String[]::new);\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Annotation type \'org.eclipse.jdt.annotation.NonNull\' cannot be found on the build path, which is implicitly needed for null analysis\n" +
- "----------\n" );
- } finally {
- deleteProject(project);
- }
+ } finally {
+ deleteProject(project);
+ }
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
index 6089b7f0e6..d3954dfd37 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 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
@@ -194,7 +194,6 @@ public class CompilerOptions {
public static final String OPTION_ReportNonnullParameterAnnotationDropped = "org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped"; //$NON-NLS-1$
public static final String OPTION_PessimisticNullAnalysisForFreeTypeVariables = "org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables"; //$NON-NLS-1$
public static final String OPTION_ReportNonNullTypeVariableFromLegacyInvocation = "org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation"; //$NON-NLS-1$
- public static final String OPTION_ReportMissingNullAnnotationImplicitlyUsed = "org.eclipse.jdt.core.compiler.problem.missingNullAnnotationImplicitlyUsed"; //$NON-NLS-1$
public static final String OPTION_ReportUnlikelyCollectionMethodArgumentType = "org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType"; //$NON-NLS-1$
public static final String OPTION_ReportUnlikelyCollectionMethodArgumentTypeStrict = "org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict"; //$NON-NLS-1$
@@ -348,7 +347,6 @@ public class CompilerOptions {
public static final int UnstableAutoModuleName = IrritantSet.GROUP2 | ASTNode.Bit26;
public static final int PreviewFeatureUsed = IrritantSet.GROUP2 | ASTNode.Bit27;
public static final int SuppressWarningsNotAnalysed = IrritantSet.GROUP2 | ASTNode.Bit28;
- public static final int MissingNullAnnotationImplicitlyUsed = IrritantSet.GROUP2 | ASTNode.Bit29;
// Severity level for handlers
@@ -785,8 +783,6 @@ public class CompilerOptions {
return OPTION_ReportPreviewFeatures;
case SuppressWarningsNotAnalysed:
return OPTION_ReportSuppressWarningNotFullyAnalysed;
- case MissingNullAnnotationImplicitlyUsed:
- return OPTION_ReportMissingNullAnnotationImplicitlyUsed;
}
return null;
}
@@ -1028,8 +1024,7 @@ public class CompilerOptions {
OPTION_ReportUnlikelyEqualsArgumentType,
OPTION_ReportAPILeak,
OPTION_ReportPreviewFeatures,
- OPTION_ReportSuppressWarningNotFullyAnalysed,
- OPTION_ReportMissingNullAnnotationImplicitlyUsed
+ OPTION_ReportSuppressWarningNotFullyAnalysed
};
return result;
}
@@ -1106,7 +1101,6 @@ public class CompilerOptions {
case NonnullParameterAnnotationDropped:
case PessimisticNullAnalysisForFreeTypeVariables:
case NonNullTypeVariableFromLegacyInvocation:
- case MissingNullAnnotationImplicitlyUsed:
return "null"; //$NON-NLS-1$
case FallthroughCase :
return "fallthrough"; //$NON-NLS-1$
@@ -1386,7 +1380,6 @@ public class CompilerOptions {
optionsMap.put(OPTION_EnablePreviews, this.enablePreviewFeatures ? ENABLED : DISABLED);
optionsMap.put(OPTION_ReportPreviewFeatures, getSeverityString(PreviewFeatureUsed));
optionsMap.put(OPTION_ReportSuppressWarningNotFullyAnalysed, getSeverityString(SuppressWarningsNotAnalysed));
- optionsMap.put(OPTION_ReportMissingNullAnnotationImplicitlyUsed, getSeverityString(MissingNullAnnotationImplicitlyUsed));
return optionsMap;
}
@@ -1963,7 +1956,6 @@ public class CompilerOptions {
this.pessimisticNullAnalysisForFreeTypeVariablesEnabled = true;
}
if ((optionValue = optionsMap.get(OPTION_ReportNonNullTypeVariableFromLegacyInvocation)) != null) updateSeverity(NonNullTypeVariableFromLegacyInvocation, optionValue);
- if ((optionValue = optionsMap.get(OPTION_ReportMissingNullAnnotationImplicitlyUsed)) != null) updateSeverity(MissingNullAnnotationImplicitlyUsed, optionValue);
}
// Javadoc options
@@ -2256,7 +2248,6 @@ public class CompilerOptions {
buf.append("\n\t- Unused Type Parameter: ").append(getSeverityString(UnusedTypeParameter)); //$NON-NLS-1$
buf.append("\n\t- pessimistic null analysis for free type variables: ").append(getSeverityString(PessimisticNullAnalysisForFreeTypeVariables)); //$NON-NLS-1$
buf.append("\n\t- report unsafe nonnull return from legacy method: ").append(getSeverityString(NonNullTypeVariableFromLegacyInvocation)); //$NON-NLS-1$
- buf.append("\n\t- report missing null annotation, which is implicitly used: ").append(getSeverityString(MissingNullAnnotationImplicitlyUsed)); //$NON-NLS-1$
buf.append("\n\t- unlikely argument type for collection methods: ").append(getSeverityString(UnlikelyCollectionMethodArgumentType)); //$NON-NLS-1$
buf.append("\n\t- unlikely argument type for collection methods, strict check against expected type: ").append(this.reportUnlikelyCollectionMethodArgumentTypeStrict ? ENABLED : DISABLED); //$NON-NLS-1$
buf.append("\n\t- unlikely argument types for equals(): ").append(getSeverityString(UnlikelyEqualsArgumentType)); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
index fdb80eca5d..72ae67a1fc 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 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
@@ -141,8 +141,7 @@ public class IrritantSet {
// default errors IF AnnotationBasedNullAnalysis is enabled:
COMPILER_DEFAULT_ERRORS.set(
CompilerOptions.NullSpecViolation
- |CompilerOptions.NullAnnotationInferenceConflict
- |CompilerOptions.MissingNullAnnotationImplicitlyUsed);
+ |CompilerOptions.NullAnnotationInferenceConflict);
ALL.setAll();
HIDING
@@ -159,8 +158,7 @@ public class IrritantSet {
.set(CompilerOptions.NonnullParameterAnnotationDropped)
.set(CompilerOptions.MissingNonNullByDefaultAnnotation)
.set(CompilerOptions.PessimisticNullAnalysisForFreeTypeVariables)
- .set(CompilerOptions.NonNullTypeVariableFromLegacyInvocation)
- .set(CompilerOptions.MissingNullAnnotationImplicitlyUsed);
+ .set(CompilerOptions.NonNullTypeVariableFromLegacyInvocation);
RESTRICTION.set(CompilerOptions.DiscouragedReference);
STATIC_ACCESS.set(CompilerOptions.NonStaticAccessToStatic);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 27646d89de..74b69a03a9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -498,8 +498,6 @@ public static int getIrritant(int problemID) {
case IProblem.RedundantNullDefaultAnnotationLocal:
case IProblem.RedundantNullDefaultAnnotationField:
return CompilerOptions.RedundantNullAnnotation;
- case IProblem.MissingNullAnnotationImplicitlyUsed:
- return CompilerOptions.MissingNullAnnotationImplicitlyUsed;
case IProblem.BoxingConversion :
case IProblem.UnboxingConversion :
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
index 62e2416edc..3b56560176 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 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
@@ -2070,20 +2070,7 @@ public final class JavaCore extends Plugin {
* @category CompilerOptionID
*/
public static final String COMPILER_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION = JavaCore.PLUGIN_ID+".compiler.problem.nonnullTypeVariableFromLegacyInvocation"; //$NON-NLS-1$
-
- /**
- * Compiler option ID: Reporting when annotation based null analysis misses an annotation type.
- * <p>When enabled, the compiler will issue an error or warning against some Java expressions with
- * known nullness, if a corresponding null annotation cannot be found on the build path.</p>
- * <dl>
- * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.missingNullAnnotationImplicitlyUsed"</code></dd>
- * <dt>Possible values:</dt><dd><code>{ "error", "warning", "info", "ignore" }</code></dd>
- * <dt>Default:</dt><dd><code>"error"</code></dd>
- * </dl>
- * @since 3.21
- * @category CompilerOptionID
- */
- public static final String COMPILER_PB_MISSING_NULL_ANNOTATION_IMPLICITLY_USED = JavaCore.PLUGIN_ID+".compiler.problem.missingNullAnnotationImplicitlyUsed"; //$NON-NLS-1$
+
/**
* Compiler option ID: Setting Source Compatibility Mode.
* <p>Specify whether which source level compatibility is used. From 1.4 on, <code>'assert'</code> is a keyword

Back to the top