Proposal: Warnings for unnecessary warning suppression

Archie Cobbs archie.cobbs at gmail.com
Wed May 7 18:26:10 UTC 2025


I'd like to restart this discussion of JDK-8344159
<https://bugs.openjdk.org/browse/JDK-8344159>  - "Add lint warnings for
unnecessary warning suppression"

Note, this is likely not destined for JDK 25. I'm bringing it up now simply
because some refactoring that arose from the previous discussion back in
November (which is here
<https://mail.openjdk.org/pipermail/compiler-dev/2024-November/028573.html>)
is now mostly done.

I think a fair summary of the current state is: Having the compiler emit
warnings for unnecessary warning suppression is considered a useful idea in
principle, but it's unclear what is the best way to configure/enable that
functionality in the compiler.

In particular, there are subtle corner cases that could be problematic if
these warnings were enabled by -Xlint:all, especially for -Werror builds.

Also complicating things, there are two different ways to suppress
warnings, @SuppressWarnings("foo") and -Xlint:-foo and for similar "corner
case" reasons they need to be configurable separately.

There is a draft <https://bugs.openjdk.org/browse/JDK-8356043>CSR
<https://bugs.openjdk.org/browse/JDK-8356043> that gives an overview of the
current prototype, which proposes to add two new lint categories. If you
are interested in this topic please review the CSR and its comments and let
me know if you have any thoughts or suggestions - but I'm trying to move
the design discussion to this mailing list so follow-up here please.

Here's a quick summary of my latest thinking...

There is value in defining lint categories for these warnings; the main
problem is that including those categories in -Xlint:all may be too
aggressive - at least for now.

So I think we should simply exclude these new lint categories from
-Xlint:all. I'll note that -Xlint:all and -Xlint are synonyms, and the
documentation for -Xlint says "Enable recommended warning categories", so
this is within the existing meaning of this flag.

In the future, if the suppression warnings are deemed sufficiently
advantageous, we could always add them to -Xlint:all. Until if/when that
happens, if you want to enable all lint categories including suppression
then you will have to add it explicitly via -Xlint:all,suppression, etc.

Does this approach sound reasonable?

Thanks,
-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250507/6ebb7dff/attachment-0001.htm>


More information about the compiler-dev mailing list