Integrated: 8374718: Generation of CompilerProperties can fail in subtle ways
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Jan 8 10:27:39 UTC 2026
On Wed, 7 Jan 2026 13:17:22 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> [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.
This pull request has now been integrated.
Changeset: 904ba5f5
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/904ba5f5ed7d3ac1a3606ff7532ba3c206a2d9b9
Stats: 21 lines in 3 files changed: 13 ins; 4 del; 4 mod
8374718: Generation of CompilerProperties can fail in subtle ways
Reviewed-by: jlahoda
-------------
PR: https://git.openjdk.org/jdk/pull/29090
More information about the build-dev
mailing list