8374718: Generation of CompilerProperties can fail in subtle ways

Reviewed-by: jlahoda
This commit is contained in:
Maurizio Cimadamore 2026-01-08 10:24:03 +00:00
parent 067fd3cb2f
commit 904ba5f5ed
3 changed files with 17 additions and 8 deletions

View File

@ -286,7 +286,7 @@ public class ClassGenerator {
diagnosticFlags.isEmpty() ? diagnosticFlags.isEmpty() ?
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() : StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags), StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""), StubKind.LINT_CATEGORY.format(toLintFieldName(lintCategory)),
"\"" + keyParts[0] + "\"", "\"" + keyParts[0] + "\"",
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
javadoc); javadoc);
@ -314,7 +314,7 @@ public class ClassGenerator {
diagnosticFlags.isEmpty() ? diagnosticFlags.isEmpty() ?
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() : StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags), StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""), StubKind.LINT_CATEGORY.format(toLintFieldName(lintCategory)),
"\"" + keyParts[0] + "\"", "\"" + keyParts[0] + "\"",
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
argNames.stream().collect(Collectors.joining(", "))); argNames.stream().collect(Collectors.joining(", ")));
@ -329,6 +329,11 @@ public class ClassGenerator {
} }
} }
String toLintFieldName(String lintCategory) {
return lintCategory.toUpperCase()
.replaceAll("-", "_");
}
/** /**
* Form the name of a factory method/field given a resource key. * Form the name of a factory method/field given a resource key.
*/ */

View File

@ -87,7 +87,7 @@ suppress.warnings=\
@SuppressWarnings("rawtypes")\n @SuppressWarnings("rawtypes")\n
lint.category=\ lint.category=\
LintCategory.get({0}).get() LintCategory.{0}
diagnostic.flags.empty=\ diagnostic.flags.empty=\
EnumSet.noneOf(DiagnosticFlag.class) EnumSet.noneOf(DiagnosticFlag.class)

View File

@ -37,11 +37,7 @@ import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.sun.tools.javac.main.Option; import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.LintWarning;
import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
@ -178,6 +174,14 @@ public class Lint {
/** /**
* Categories of warnings that can be generated by the compiler. * Categories of warnings that can be generated by the compiler.
* Each lint category has a logical name (a string), which is the string used e.g. in a {@code SuppressWarning} annotation.
* To ensure automation, the enum field name for a lint category string {@code C} should be obtained by:
* <ol>
* <li>capitalize all the letters in {@code C}, and</li>
* <li>replacing any occurrence of {@code -} with {@code _}</li>
* </ol>
* For instance, the lint category string {@code dangling-doc-comments} corresponds to the enum field
* {@code DANGLING_DOC_COMMENTS}.
*/ */
public enum LintCategory { public enum LintCategory {
/** /**
@ -320,7 +324,7 @@ public class Lint {
/** /**
* Warn about unchecked operations on raw types. * Warn about unchecked operations on raw types.
*/ */
RAW("rawtypes"), RAWTYPES("rawtypes"),
/** /**
* Warn about use of deprecated-for-removal items. * Warn about use of deprecated-for-removal items.