Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-09-17 17:35:51 -0400
committerStephan Herrmann2019-09-18 16:44:53 -0400
commitc842004634d661ef8d9d485e77e9c84af231e888 (patch)
treed199a1c99cb04f7b74801158bb6d56af236f088a
parent6a8cee1126829229d648db4ae0e5a6b70a5d4f13 (diff)
downloadeclipse.jdt.core-I20190918-1800.tar.gz
eclipse.jdt.core-I20190918-1800.tar.xz
eclipse.jdt.core-I20190918-1800.zip
Bug 541225 - The message "At least one of the problems in category 'XXX'I20190918-1800
is not analysed due to a compiler option being ignored" is confusing Change-Id: I70e8323c8b9ca57bdb7070ea3775bffcd26500c8
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java65
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java1
-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/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java5
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java22
7 files changed, 108 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
index 9ef55a2e05..85a784d961 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
@@ -8201,6 +8201,71 @@ public void test245() {
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation
+public void test245_ignored() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING);
+ options.put(CompilerOptions.OPTION_ReportSuppressWarningNotFullyAnalysed, CompilerOptions.IGNORE);
+ enableAllWarningsForIrritants(options, IrritantSet.UNUSED);
+ this.runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " \n" +
+ " @SuppressWarnings({\"unchecked\",\"unused\"})\n" +
+ " void foo() {\n" +
+ " \n" +
+ " }\n" +
+ "} \n",
+ },
+ null, options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " @SuppressWarnings({\"unchecked\",\"unused\"})\n" +
+ " ^^^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"unused\")\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation
+public void test245_error() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING);
+ options.put(CompilerOptions.OPTION_ReportSuppressWarningNotFullyAnalysed, CompilerOptions.ERROR);
+ enableAllWarningsForIrritants(options, IrritantSet.UNUSED);
+ this.runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " \n" +
+ " @SuppressWarnings({\"unchecked\",\"unused\"})\n" +
+ " void foo() {\n" +
+ " \n" +
+ " }\n" +
+ "} \n",
+ },
+ null, options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " @SuppressWarnings({\"unchecked\",\"unused\"})\n" +
+ " ^^^^^^^^^^^\n" +
+ "At least one of the problems in category \'unchecked\' is not analysed due to a compiler option being ignored\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 3)\n" +
+ " @SuppressWarnings({\"unchecked\",\"unused\"})\n" +
+ " ^^^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"unused\")\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation
public void test246() {
Map options = getCompilerOptions();
options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
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 d4aa47bc36..6451a17aaa 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
@@ -1097,6 +1097,7 @@ public void test012b(){
" <option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarnings\" value=\"enabled\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed\" value=\"info\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.tasks\" 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 5283c50b11..4d3f57f1ed 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
@@ -1879,6 +1879,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
expectedProblemAttributes.put("PotentialNullUnboxing", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
expectedProblemAttributes.put("PotentialNullMessageSendReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
+ expectedProblemAttributes.put("ProblemNotAnalysed", new ProblemAttributes(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS_NOT_FULLY_ANALYSED));
expectedProblemAttributes.put("ProviderMethodOrConstructorRequiredForServiceImpl", SKIP);
expectedProblemAttributes.put("PublicClassMustMatchFileName", SKIP);
expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", SKIP);
@@ -2097,7 +2098,6 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("DisallowedExplicitThisParameter", SKIP);
expectedProblemAttributes.put("IllegalArrayOfUnionType", SKIP);
expectedProblemAttributes.put("IllegalArrayTypeInIntersectionCast", SKIP);
- expectedProblemAttributes.put("ProblemNotAnalysed", SKIP);
expectedProblemAttributes.put("VarCannotBeMixedWithNonVarParams", SKIP);
expectedProblemAttributes.put("VarIsNotAllowedHere", SKIP);
expectedProblemAttributes.put("VarIsReserved", SKIP);
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 5fda6a7089..b7c7458b75 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, 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
@@ -205,6 +205,8 @@ public class CompilerOptions {
public static final String OPTION_EnablePreviews = "org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures"; //$NON-NLS-1$
public static final String OPTION_ReportPreviewFeatures = "org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures"; //$NON-NLS-1$
+ public static final String OPTION_ReportSuppressWarningNotFullyAnalysed = "org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed"; //$NON-NLS-1$
+
// Internally used option to allow debug framework compile evaluation snippets in context of modules, see bug 543604
public static final String OPTION_JdtDebugCompileMode = "org.eclipse.jdt.internal.debug.compile.mode"; //$NON-NLS-1$
@@ -343,6 +345,7 @@ public class CompilerOptions {
public static final int APILeak = IrritantSet.GROUP2 | ASTNode.Bit25;
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;
// Severity level for handlers
@@ -777,6 +780,8 @@ public class CompilerOptions {
return OPTION_ReportUnstableAutoModuleName;
case PreviewFeatureUsed:
return OPTION_ReportPreviewFeatures;
+ case SuppressWarningsNotAnalysed:
+ return OPTION_ReportSuppressWarningNotFullyAnalysed;
}
return null;
}
@@ -1017,7 +1022,8 @@ public class CompilerOptions {
OPTION_ReportUnlikelyCollectionMethodArgumentType,
OPTION_ReportUnlikelyEqualsArgumentType,
OPTION_ReportAPILeak,
- OPTION_ReportPreviewFeatures
+ OPTION_ReportPreviewFeatures,
+ OPTION_ReportSuppressWarningNotFullyAnalysed
};
return result;
}
@@ -1372,6 +1378,7 @@ public class CompilerOptions {
optionsMap.put(OPTION_ReportUnstableAutoModuleName, getSeverityString(UnstableAutoModuleName));
optionsMap.put(OPTION_EnablePreviews, this.enablePreviewFeatures ? ENABLED : DISABLED);
optionsMap.put(OPTION_ReportPreviewFeatures, getSeverityString(PreviewFeatureUsed));
+ optionsMap.put(OPTION_ReportSuppressWarningNotFullyAnalysed, getSeverityString(SuppressWarningsNotAnalysed));
return optionsMap;
}
@@ -2095,6 +2102,8 @@ public class CompilerOptions {
}
if ((optionValue = optionsMap.get(OPTION_ReportPreviewFeatures)) != null)
updateSeverity(PreviewFeatureUsed, optionValue);
+ if ((optionValue = optionsMap.get(OPTION_ReportSuppressWarningNotFullyAnalysed)) != null)
+ updateSeverity(SuppressWarningsNotAnalysed, optionValue);
if ((optionValue = optionsMap.get(OPTION_JdtDebugCompileMode)) != null) {
if (ENABLED.equals(optionValue)) {
@@ -2243,6 +2252,7 @@ public class CompilerOptions {
buf.append("\n\t- unlikely argument types for equals(): ").append(getSeverityString(UnlikelyEqualsArgumentType)); //$NON-NLS-1$
buf.append("\n\t- API leak: ").append(getSeverityString(APILeak)); //$NON-NLS-1$
buf.append("\n\t- unstable auto module name: ").append(getSeverityString(UnstableAutoModuleName)); //$NON-NLS-1$
+ buf.append("\n\t- SuppressWarnings not fully analysed: ").append(getSeverityString(SuppressWarningsNotAnalysed)); //$NON-NLS-1$
return buf.toString();
}
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 a12103c4ab..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, 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
@@ -80,12 +80,13 @@ public class IrritantSet {
public static final IrritantSet PREVIEW = new IrritantSet(CompilerOptions.PreviewFeatureUsed);
public static final IrritantSet COMPILER_DEFAULT_ERRORS = new IrritantSet(0); // no optional error by default
public static final IrritantSet COMPILER_DEFAULT_WARNINGS = new IrritantSet(0); // see static initializer below
- public static final IrritantSet COMPILER_DEFAULT_INFOS = new IrritantSet(0); // As of now, no default values
+ public static final IrritantSet COMPILER_DEFAULT_INFOS = new IrritantSet(0); // see static initializer below
static {
COMPILER_DEFAULT_INFOS
// group-2 infos enabled by default
.set(
- CompilerOptions.UnlikelyEqualsArgumentType);
+ CompilerOptions.UnlikelyEqualsArgumentType
+ | CompilerOptions.SuppressWarningsNotAnalysed);
COMPILER_DEFAULT_WARNINGS
// group-0 warnings enabled by default
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 50ebb1c56d..69bf233605 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
@@ -668,6 +668,9 @@ public static int getIrritant(int problemID) {
return CompilerOptions.UnstableAutoModuleName;
case IProblem.PreviewFeatureUsed:
return CompilerOptions.PreviewFeatureUsed;
+
+ case IProblem.ProblemNotAnalysed:
+ return CompilerOptions.SuppressWarningsNotAnalysed;
}
return 0;
}
@@ -1689,8 +1692,6 @@ public int computeSeverity(int problemID){
return ProblemSeverities.Warning;
case IProblem.IllegalUseOfUnderscoreAsAnIdentifier:
return this.underScoreIsError ? ProblemSeverities.Error : ProblemSeverities.Warning;
- case IProblem.ProblemNotAnalysed:
- return ProblemSeverities.Info; // Not configurable
}
int irritant = getIrritant(problemID);
if (irritant != 0) {
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 a0a596de5b..7d8ad5faf4 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
@@ -1654,6 +1654,28 @@ public final class JavaCore extends Plugin {
*/
public static final String COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME = PLUGIN_ID + ".compiler.problem.unstableAutoModuleName"; //$NON-NLS-1$
+ /**
+ * Compiler option ID: Reporting when a {@code @SuppressWarnings} annotation might be unused, but exact information is not available.
+ * <p>
+ * This issue occurs when a suppress warnings token (like, e.g., {@code "unused"}) represents a group of problems,
+ * and some of the problems in that group are currently disabled (configured as "ignore").
+ * In this situation the compiler may not know if none of the problems in that group could be found within the
+ * annotated code section.
+ * <p>
+ * When enabled, the compiler will issue an error, warning or info when a {@code @SuppressWarnings} annotation
+ * was not observed to be necessary, but analysis of the suppressed group of problems was incomplete.
+ *
+ * <dl>
+ * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed"</code></dd>
+ * <dt>Possible values:</dt>
+ * <dd><code>{ "error", "warning", "info", "ignore" }</code></dd>
+ * <dt>Default:</dt><dd><code>"info"</code></dd>
+ * </dl>
+ *
+ * @since 3.20
+ * @category CompilerOptionID
+ */
+ public static final String COMPILER_PB_SUPPRESS_WARNINGS_NOT_FULLY_ANALYSED = PLUGIN_ID + ".compiler.problem.suppressWarningsNotFullyAnalysed"; //$NON-NLS-1$
/**
* Compiler option ID: Annotation-based Null Analysis.

Back to the top