From 9e788319c5109a86e1bc1ec3417b3301aa1d0153 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Wed, 18 Jun 2025 16:06:32 -0500 Subject: [PATCH] Ensure that "-Xlint:none" still works for the affected warnings. The extra checks for "-Xlint:none" are needed now because of JDK-8352612, which changed the behavior of "-Xlint:none" to no longer imply "-nowarn", which allowed the affected warnings to get away with skipping that check. --- .../com/sun/tools/javac/comp/Modules.java | 2 +- .../com/sun/tools/javac/main/Arguments.java | 4 +- .../com/sun/tools/javac/util/Options.java | 41 ++++++++++++++++++- .../tools/javac/lint/LintOptions.java | 2 + 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java index a159793fe32..0015b73631a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java @@ -205,7 +205,7 @@ public class Modules extends JCTree.Visitor { allowAccessIntoSystem = options.isUnset(Option.RELEASE); - lintOptions = !options.isExplicitlyDisabled(Option.XLINT, LintCategory.OPTIONS); + lintOptions = !options.isDisabled(Option.XLINT, LintCategory.OPTIONS); multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH); ClassWriter classWriter = ClassWriter.instance(context); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java index 9e3a978c3bc..b1dfb0378bd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java @@ -503,7 +503,7 @@ public class Arguments { } } else { // single-module or legacy mode - boolean lintPaths = !options.isExplicitlyDisabled(Option.XLINT, LintCategory.PATH); + boolean lintPaths = !options.isDisabled(Option.XLINT, LintCategory.PATH); if (lintPaths) { Path outDirParent = outDir.getParent(); if (outDirParent != null && Files.exists(outDirParent.resolve("module-info.class"))) { @@ -576,7 +576,7 @@ public class Arguments { reportDiag(Errors.SourcepathModulesourcepathConflict); } - boolean lintOptions = !options.isExplicitlyDisabled(Option.XLINT, LintCategory.OPTIONS); + boolean lintOptions = !options.isDisabled(Option.XLINT, LintCategory.OPTIONS); if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) { if (fm instanceof BaseFileManager baseFileManager) { if (source.compareTo(Source.JDK8) <= 0) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java index c882fb4cf8a..cbc69feb421 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java @@ -171,12 +171,46 @@ public class Options { return !isSet(option, value); } + /** + * Determine if a specific {@link LintCategory} is enabled via a custom + * option flag of the form {@code -Flag}, {@code -Flag:all}, or {@code -Flag:key}. + * + *

+ * Note: It's possible the category was also disabled; this method does not check that. + * + * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) + * @param lc the {@link LintCategory} in question + * @return true if {@code lc} has been enabled + */ + public boolean isEnabled(Option option, LintCategory lc) { + Option custom = option.getCustom(); + return isExplicitlyEnabled(option, lc) || isSet(custom) || isSet(custom, Option.LINT_CUSTOM_ALL); + } + + /** + * Determine if a specific {@link LintCategory} is disabled via a custom + * option flag of the form {@code -Flag:none} or {@code -Flag:-key}. + * + *

+ * Note: It's possible the category was also enabled; this method does not check that. + * + * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) + * @param lc the {@link LintCategory} in question + * @return true if {@code lc} has been disabled + */ + public boolean isDisabled(Option option, LintCategory lc) { + return isExplicitlyDisabled(option, lc) || isSet(option.getCustom(), Option.LINT_CUSTOM_NONE); + } + /** * Determine if a specific {@link LintCategory} is explicitly enabled via a custom * option flag of the form {@code -Flag:key}. * *

- * Note: It's possible the category was also explicitly disabled; this method does not check that. + * Note: This does not check for option flags of the form {@code -Flag} or {@code -Flag:all}. + * + *

+ * Note: It's possible the category was also disabled; this method does not check that. * * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) * @param lc the {@link LintCategory} in question @@ -192,7 +226,10 @@ public class Options { * option flag of the form {@code -Flag:-key}. * *

- * Note: It's possible the category was also explicitly enabled; this method does not check that. + * Note: This does not check for an option flag of the form {@code -Flag:none}. + * + *

+ * Note: It's possible the category was also enabled; this method does not check that. * * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) * @param lc the {@link LintCategory} in question diff --git a/test/langtools/tools/javac/lint/LintOptions.java b/test/langtools/tools/javac/lint/LintOptions.java index b5825fce728..10def72a31a 100644 --- a/test/langtools/tools/javac/lint/LintOptions.java +++ b/test/langtools/tools/javac/lint/LintOptions.java @@ -31,6 +31,8 @@ * @compile/fail/ref=LintOptions.out -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:options LintOptions.java * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:-options LintOptions.java * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:options -Xlint:-options LintOptions.java + * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:none LintOptions.java + * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:options -Xlint:none LintOptions.java */ class LintOptions { }