RFR: 8359493: Refactor how aggregated mandatory warnings are handled in the compiler

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Jun 23 09:51:29 UTC 2025


On Fri, 13 Jun 2025 21:25:54 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> The compiler's handling of the aggregation of mandatory warnings into "notes" at the end of compilation can be refactored to simplify the code.
> 
> The `JCDiagnostic` class supports flags that alter how warnings are handled, e.g., `MANDATORY`, `NON_DEFERRABLE`, etc. So instead of having to log aggregated mandatory warnings through a separate channel (the `MandatoryWarningHandler`), these warnings could instead be logged just like any other warning, but with an `AGGREGATED` flag added. The actual aggregation can then be handled "behind the scenes" by the logging subsystem.
> 
> This will also make it easier to implement `@SuppressAnnotations` support for parser/tokenizer warnings which require aggregated mandatory warning notes such as warnings for preview features.

src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java line 165:

> 163:      * @param flags      Any additional flags required
> 164:      */
> 165:     public void warning(Warning warningKey, DiagnosticFlag... flags) {

I'm not sure about these changes to the `warning` method. The reason being that this PR doesn't seem to require such changes. And note that, with this change, all calls to `Log.warning` become variadic -- meaning the compiler will have to at least allocate an empty array. I'm not sure if this is enough to cause a regression, but if not necessary, I'd prefer to revert these changes, also noting that `error` and `note` have variants that do not accept flags.

src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java line 197:

> 195:      *  @param flags         Any additional flags required
> 196:      */
> 197:     public void mandatoryWarning(DiagnosticPosition pos, Warning warningKey, DiagnosticFlag... flags) {

Note: this method is already some kind of special wrapper around `Log.warning` which always sets the mandatory flag. I wonder if, maybe, we could just tweak this method to take a boolean parameter telling whether to aggregate or not, and then deal with the flags internally?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25810#discussion_r2161185696
PR Review Comment: https://git.openjdk.org/jdk/pull/25810#discussion_r2161188294


More information about the compiler-dev mailing list