From 0ef67a45e00f8eff20128cb4e250ab38bf9c3cb1 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Sat, 30 Aug 2025 14:01:58 -0500 Subject: [PATCH] Minor cleanups. --- .../com/sun/tools/javac/code/LintMapper.java | 2 +- .../javac/lint/SuppressionWarningTest.java | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java index ebcff99963b..82e7f00f543 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java @@ -77,7 +77,7 @@ import com.sun.tools.javac.util.Log; * *

* Validation events "bubble up" the source tree until either they are "caught" by a {@code @SuppressWarnings} - * annotation, or they escape the file entirely. Being "caught" validates the corresponding suppression. + * annotation, or they escape the file entirely. Being caught validates the corresponding suppression. * A suppression that is never caught (i.e., never validated) is unnecessary. * *

diff --git a/test/langtools/tools/javac/lint/SuppressionWarningTest.java b/test/langtools/tools/javac/lint/SuppressionWarningTest.java index 883f35e15be..50ff443d975 100644 --- a/test/langtools/tools/javac/lint/SuppressionWarningTest.java +++ b/test/langtools/tools/javac/lint/SuppressionWarningTest.java @@ -649,8 +649,8 @@ public class SuppressionWarningTest extends TestRunner { test.runTestsMulti(m -> switch (m.getName()) { case "testSuppressWarnings" -> SUPPRESS_WARNINGS_TEST_CASES.stream() .map(testCase -> new Object[] { testCase }); - case "testUselessAnnotation" -> Stream.of(LintCategory.values()) - .filter(category -> category != LintCategory.SUPPRESSION) + case "testUselessAnnotation", + "testUselessLintFlag" -> Stream.of(LintCategory.values()) .map(category -> new Object[] { category }); case "testSelfSuppression" -> Stream.of(RAW, SUPPRESSION) .map(category -> new Object[] { category }); @@ -747,7 +747,7 @@ public class SuppressionWarningTest extends TestRunner { // Try all combinations of lint flags for (boolean enableCategory : booleans) { // [-]category - for (boolean enableSuppression : booleans) { // [-]suppression + for (boolean enableSuppression : booleans) { // [-]suppression // Special case when category is SUPPRESSION itself: avoid a contradiction if (category == LintCategory.SUPPRESSION && enableCategory != enableSuppression) @@ -837,7 +837,7 @@ public class SuppressionWarningTest extends TestRunner { out.print(buf); throw e; } - } + } } } } } @@ -845,8 +845,10 @@ public class SuppressionWarningTest extends TestRunner { // Test a @SuppressWarning annotation that suppresses nothing @Test public void testUselessAnnotation(LintCategory category) throws Exception { - compileAndExpectWarning( - "compiler.warn.unnecessary.warning.suppression", + String warningKey = category != LintCategory.SUPPRESSION ? // @SuppressWarnings("suppression") can never be useless! + "compiler.warn.unnecessary.warning.suppression" : null; + compileAndExpect( + warningKey, String.format( """ @SuppressWarnings(\"%s\") @@ -927,7 +929,14 @@ public class SuppressionWarningTest extends TestRunner { String.format("-Xlint:%s", SUPPRESSION.option)); } - public void compileAndExpectWarning(String errorKey, String source, String... flags) throws Exception { + public void compileAndExpect(String warningKey, String source, String... flags) throws Exception { + if (warningKey != null) + compileAndExpectWarning(warningKey, source, flags); + else + compileAndExpectSuccess(source, flags); + } + + public void compileAndExpectWarning(String warningKey, String source, String... flags) throws Exception { // Setup source & destination diretories Path base = Paths.get("compileAndExpectWarning"); @@ -938,10 +947,10 @@ public class SuppressionWarningTest extends TestRunner { // Compile sources and verify we got the warning List log = compile(base, Task.Expect.FAIL, addWerror(flags)); - if (log.stream().noneMatch(line -> line.contains(errorKey))) { + if (log.stream().noneMatch(line -> line.contains(warningKey))) { throw new AssertionError(String.format( "did not find \"%s\" in log output:%n %s", - errorKey, log.stream().collect(Collectors.joining("\n ")))); + warningKey, log.stream().collect(Collectors.joining("\n ")))); } }