RFR: 8354071: Add LintCategory property indicating whether @SuppressWarnings is supported

Archie Cobbs acobbs at openjdk.org
Wed Apr 9 13:53:34 UTC 2025


On Wed, 9 Apr 2025 08:31:20 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This is split off as a sub-task of [JDK-8224228](https://bugs.openjdk.org/browse/JDK-8224228), which seeks to add `@SuppressWarnings` support for lexical features.
>> 
>> Lint warnings that are subject to suppression via `@SuppressWarnings` must be deferred until attribution, because until then we can't determine whether they are suppressed or not.
>> 
>> Whether a lint warning is subject to suppression via `@SuppressWarnings` is a function of the associated `LintCategory`, not the warning itself. For example `LintCategory.OPTIONS` is not, so an occurrence of `@SuppressWarnings("options")` is meaningless and would be ignored.
>> 
>> This information is needed in the upcoming refactoring. We can facilitate that very simply by adding a boolean property to the `LintCategory` enum.
>> 
>> In addition, this permits a small optimization to be added to `Lint.suppressionsFrom()`.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java line 377:
> 
>> 375:          * This category is not supported by {@code @SuppressWarnings}.
>> 376:          */
>> 377:         TEXT_BLOCKS("text-blocks", false),
> 
> For this I'm a bit unsure -- the warning here is not unsuppressible by design, but, rather because of a deficiency in how suppression works. So seeing a "bug" reified in a flag here seems odd. At the very least this one seems different from the others -- where effectively there's no place to even put the `SuppressWarning` ?

The intent was for this field to represent what's actually (currently) true in the compiler - which is that `@SuppressWarnings("text-blocks")` is not supported - and then revert this part of the change when [JDK-8224228](https://bugs.openjdk.org/browse/JDK-8224228) gets fixed. But we could also do that preemptively if you prefer - just let me know.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24529#discussion_r2035425410


More information about the compiler-dev mailing list