RFR: 8344159: Add lint warnings for unnecessary warning suppression
Pavel Rappo
prappo at openjdk.org
Wed Sep 24 16:36:32 UTC 2025
On Wed, 24 Sep 2025 14:58:38 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
> > Thanks for this explanation. I can now see what you mean in the _Different Compiler Versions_ section of the CSR. That's some quality reasoning and future-proofing.
>
> Credit goes to @jddarcy for pinpointing those possible traps.
>
> > I suppose, it would unnecessarily complicate the design if we stipulate that `@SuppressWarnings("suppression")` should only emit a warning if there are no `@SuppressWarnings` in any of the _child scopes_. Note, not just ineffective `@SuppressWarnings`s, but none at all.
>
> Here's an analogy that helps me justify the current design, fwiw. Have you ever been to New York or another city and walked by an otherwise completely blank wall that has "POST NO BILLS" signs stuck to it, and then thought about how ironic it is that posting bills is required in order to notify people not to post bills?
>
> Sticking `@SuppressWarnings("suppression")` on a declaration is analogous. We're posting a notification not to do something, even though the notification itself risks doing it. But that's OK and we make a special exception for it.
>
> If we didn't make such exceptions, then when you walked by such a wall you'd see a workman repeatedly posting and unposting the "POST NO BILLS" bills :)
That analogy is amusing, but it either barely applies here, or I'm too tired to see how it does.
In my most recent message, I mused about this: _what if `@SuppressWarnings("suppression")` were to emit a warning only if there's no `@SuppressWarnings` of any kind anywhere under it?_ This behaviour is minimally stricter than that of this PR, and is compatible with the M-N-compiler use case.
Basically, if `@SuppressWarnings("suppression")` was accidentally left with no suppressions under it, the compiler would warn you, so you could remove it. Because what's the reason for `@SuppressWarnings("suppression")` whose scope contains no suppressions?
Just to clarify, here's an example of what I mean:
@SuppressWarnings("suppression")
public void m() {
/* a method that contains no @SuppressWarnings
annotations whatsoever */
}
Here's an example of what I **don't** mean:
@SuppressWarnings("suppression")
public void m() {
/* a method that only contains @SuppressWarnings
annotations that are ineffective. That is,
annotations, that if removed, would __not__
break compilation with -Werror */
}
The idea here is to minimise the chance of `@SuppressWarnings("suppression")` becoming part of the furniture and hiding unneeded future suppressions. But maybe changing the behaviour as described above would introduce more complexity and future issues than it would catch potential bugs.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25167#issuecomment-3329793388
More information about the serviceability-dev
mailing list