From 16debaa4c3609cfe9830ee6a441a361703b45c99 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Tue, 10 Jun 2025 14:32:42 -0500 Subject: [PATCH 1/6] Small refactoring to utilize new method Options.isExplicitlyDisabled(). --- .../share/classes/com/sun/tools/javac/util/Log.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java index c7627d6e45b..6b0bea7feab 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java @@ -171,7 +171,7 @@ public class Log extends AbstractLog { lint.isEnabled(category) : // then emit if the category is enabled category.annotationSuppression ? // else emit if the category is not suppressed, where !lint.isSuppressed(category) : // ...suppression happens via @SuppressWarnings - !options.isSet(XLINT_CUSTOM, "-" + category.option); // ...suppression happens via -Xlint:-category + !options.isExplicitlyDisabled(Option.XLINT, category); // ...suppression happens via -Xlint:-category if (!emit) return; } From cde1f5ef56dd247cb6049172d9cdb4dc37cd897d Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Fri, 13 Jun 2025 16:35:08 -0500 Subject: [PATCH 2/6] Revert PR #24600 (for JDK-8354447) from this branch so it's not a dependency. --- .../danglingDocComments/DanglingDocCommentsClass.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/test/langtools/tools/javac/danglingDocComments/DanglingDocCommentsClass.java b/test/langtools/tools/javac/danglingDocComments/DanglingDocCommentsClass.java index 9d2adbc656f..3f6553d191f 100644 --- a/test/langtools/tools/javac/danglingDocComments/DanglingDocCommentsClass.java +++ b/test/langtools/tools/javac/danglingDocComments/DanglingDocCommentsClass.java @@ -45,13 +45,4 @@ public /** Misplaced: after mods. */ class DanglingDocCommentsClass /** Misplace /** Good comment. */ int i = 0; } - - /** Dangling comment X */ - - /** - * The {@code @SuppressWarnings} annotation below retroactively - * silences the warning about "Dangling comment X". - */ - @SuppressWarnings("dangling-doc-comments") - public void m5() { } -} +} \ No newline at end of file From 24df3a2e50b414c2f634dcff840462d8b4e72e99 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Fri, 13 Jun 2025 17:18:09 -0500 Subject: [PATCH 3/6] Add comment to regression test. --- test/langtools/tools/javac/6304921/TestLog.java | 1 + 1 file changed, 1 insertion(+) diff --git a/test/langtools/tools/javac/6304921/TestLog.java b/test/langtools/tools/javac/6304921/TestLog.java index 2a40c6ec4fe..8f00a14b9e2 100644 --- a/test/langtools/tools/javac/6304921/TestLog.java +++ b/test/langtools/tools/javac/6304921/TestLog.java @@ -130,6 +130,7 @@ public class TestLog log.error(tree.pos(), Errors.NotStmt); log.error(nil, Errors.NotStmt); + // some warnings that will be emitted during parsing log.warning(Warnings.ExtraneousSemicolon); log.warning(tree.pos, Warnings.ExtraneousSemicolon); log.warning(tree.pos(), Warnings.ExtraneousSemicolon); From b7adf7c439297604158fcf9909dd61c3f84e5130 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Fri, 13 Jun 2025 17:18:21 -0500 Subject: [PATCH 4/6] Revert regression test change that is no longer necessary. --- .../javac/processing/model/util/printing/module-info.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/langtools/tools/javac/processing/model/util/printing/module-info.java b/test/langtools/tools/javac/processing/model/util/printing/module-info.java index 3cf7d8425d9..5e02bd4cf42 100644 --- a/test/langtools/tools/javac/processing/model/util/printing/module-info.java +++ b/test/langtools/tools/javac/processing/model/util/printing/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ * @test * @bug 8173609 * @summary printing of modules - * @compile/ref=module-info.out -Xprint p/P.java -Xlint:-module module-info.java + * @compile/ref=module-info.out -Xprint p/P.java module-info.java */ /** From 5069bf2d66625fd220d693e49a923e0b383ced3c Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Mon, 16 Jun 2025 20:52:10 -0500 Subject: [PATCH 5/6] Restore behavior when both -Xlint:options and -Xlint:-options are given. --- .../com/sun/tools/javac/util/Options.java | 48 ++++++------------- .../tools/javac/lint/LintOptions.java | 11 +++++ .../tools/javac/lint/LintOptions.out | 4 ++ 3 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 test/langtools/tools/javac/lint/LintOptions.java create mode 100644 test/langtools/tools/javac/lint/LintOptions.out 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 63f5b0ca75a..c882fb4cf8a 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 @@ -172,55 +172,35 @@ public class Options { } /** - * Check whether the given lint category is explicitly enabled or disabled. + * Determine if a specific {@link LintCategory} is explicitly enabled via a custom + * option flag of the form {@code -Flag:key}. * *

- * If the category is neither enabled nor disabled, return the given default value. + * Note: It's possible the category was also explicitly disabled; this method does not check that. * - * @param option the plain (non-custom) option - * @param lc the {@link LintCategory} in question - * @param defaultValue presumed default value - * @return true if {@code lc} would be included - */ - public boolean isSet(Option option, LintCategory lc, boolean defaultValue) { - Option customOption = option.getCustom(); - if (lc.optionList.stream().anyMatch(alias -> isSet(customOption, alias))) { - return true; - } - if (lc.optionList.stream().anyMatch(alias -> isSet(customOption, "-" + alias))) { - return false; - } - if (isSet(option) || isSet(customOption, Option.LINT_CUSTOM_ALL)) { - return true; - } - if (isSet(customOption, Option.LINT_CUSTOM_NONE)) { - return false; - } - return defaultValue; - } - - /** - * Determine if a specific {@link LintCategory} was explicitly enabled via a custom option flag - * of the form {@code -Flag:all} or {@code -Flag:key}. - * - * @param option the option + * @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 explicitly enabled */ public boolean isExplicitlyEnabled(Option option, LintCategory lc) { - return isSet(option, lc, false); + Option customOption = option.getCustom(); + return lc.optionList.stream().anyMatch(alias -> isSet(customOption, alias)); } /** - * Determine if a specific {@link LintCategory} was explicitly disabled via a custom option flag - * of the form {@code -Flag:none} or {@code -Flag:-key}. + * Determine if a specific {@link LintCategory} is explicitly disabled via a custom + * option flag of the form {@code -Flag:-key}. * - * @param option the option + *

+ * Note: It's possible the category was also explicitly 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 explicitly disabled */ public boolean isExplicitlyDisabled(Option option, LintCategory lc) { - return !isSet(option, lc, true); + Option customOption = option.getCustom(); + return lc.optionList.stream().anyMatch(alias -> isSet(customOption, "-" + alias)); } public void put(String name, String value) { diff --git a/test/langtools/tools/javac/lint/LintOptions.java b/test/langtools/tools/javac/lint/LintOptions.java new file mode 100644 index 00000000000..81b0a0dc325 --- /dev/null +++ b/test/langtools/tools/javac/lint/LintOptions.java @@ -0,0 +1,11 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8359596 + * @summary Verify behavior when both "-Xlint:options" and "-Xlint:-options" are given + * @compile/fail/ref=LintOptions.out -Werror -XDrawDiagnostics -source 21 -target 21 LintOptions.java + * @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 + */ +class LintOptions { +} diff --git a/test/langtools/tools/javac/lint/LintOptions.out b/test/langtools/tools/javac/lint/LintOptions.out new file mode 100644 index 00000000000..020c626ee5c --- /dev/null +++ b/test/langtools/tools/javac/lint/LintOptions.out @@ -0,0 +1,4 @@ +- compiler.warn.source.no.system.modules.path: 21, (compiler.misc.source.no.system.modules.path.with.target: 21, 21) +- compiler.err.warnings.and.werror +1 error +1 warning From 8dcea7004f9ad1f3c8ee5e6aeb934ed0518a2a37 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Tue, 17 Jun 2025 08:59:59 -0500 Subject: [PATCH 6/6] No need for /nodynamiccopyright/ with this test. --- .../tools/javac/lint/LintOptions.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/langtools/tools/javac/lint/LintOptions.java b/test/langtools/tools/javac/lint/LintOptions.java index 81b0a0dc325..b5825fce728 100644 --- a/test/langtools/tools/javac/lint/LintOptions.java +++ b/test/langtools/tools/javac/lint/LintOptions.java @@ -1,5 +1,30 @@ /* - * @test /nodynamiccopyright/ + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test * @bug 8359596 * @summary Verify behavior when both "-Xlint:options" and "-Xlint:-options" are given * @compile/fail/ref=LintOptions.out -Werror -XDrawDiagnostics -source 21 -target 21 LintOptions.java