RFR: 8374718: Generation of CompilerProperties can fail in subtle ways
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Jan 7 13:28:33 UTC 2026
[This PR](https://git.openjdk.org/jdk/pull/22553) introduced a new diagnostic info line to allow warning keys to be associated with a lint category. For instance:
# lint: identity
compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class=\
attempt to synchronize on an instance of a value-based class
Is parsed at build time, and result in the following field to be added to the `CompilerProperties` class:
/**
* "attempt.to.synchronize.on.instance.of.value.based.class"
*/
public static final LintWarning AttemptToSynchronizeOnInstanceOfValueBasedClass = new LintWarning(EnumSet.noneOf(DiagnosticFlag.class), LintCategory.get("identity").get(), "compiler", "attempt.to.synchronize.on.instance.of.value.based.class");
Note that the lint category undergoes a dynamic lookup:
LintCategory.get("identity").get()
This means that if there's a typo in the compiler.properties file, the lookup will fail and the JDK build will fail in a very obscure way (see JBS for reference). To avoid this problem, this PR removes the dynamic lookup from the generated file -- that is, the code in `CompilerProperties` will be:
/**
* "attempt.to.synchronize.on.instance.of.value.based.class"
*/
public static final LintWarning AttemptToSynchronizeOnInstanceOfValueBasedClass = new LintWarning(EnumSet.noneOf(DiagnosticFlag.class), LintCategory.IDENTITY, "compiler", "attempt.to.synchronize.on.instance.of.value.based.class");
That is, the lint category string in `compiler.properties` is turned into a field name, first by capitalizing all the chars, then by replacing `-` with `_`. This ensures that if a lint category is mispelled in `compiler.prooprties`, the resulting generated code will fail to compile.
The small price we have to pay for this is that we need to make sure that the naming of the lint category enum fields are consistent -- to this end the lint field `RAW` had to be renamed to `RAWTYPES`. But that was the only exception to the unwritten rule. I have also added a comment to capture this rule.
-------------
Commit messages:
- Initial push
Changes: https://git.openjdk.org/jdk/pull/29090/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29090&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8374718
Stats: 21 lines in 3 files changed: 13 ins; 4 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/29090.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29090/head:pull/29090
PR: https://git.openjdk.org/jdk/pull/29090
More information about the build-dev
mailing list