RFR: 8344159: Add lint warnings for unnecessary warning suppression

Pavel Rappo prappo at openjdk.org
Tue Sep 23 21:27:56 UTC 2025


On Tue, 23 Sep 2025 21:20:19 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> > While I've read the CSR, I haven't read any compiler-dev thread(s). At least not carefully. I also haven't seen the diff.
> 
> FWIW there is a discussion thread (starting [here](https://mail.openjdk.org/pipermail/compiler-dev/2024-November/028573.html)), but it's been on/off since November 2024.
> 
> > IIUC, this annotation can be applied to itself: `@SupressWarnings("suppression")`. Has the scope of `@SupressWarnings` always included the annotation itself, or it's something that you had to tweak in this PR?
> 
> Astute question :) In general, it's completely up to the particular warning. The scope can even extend _before_ the annotation; this is the case with `"dangling-doc-comments"` (see #24600). But normally the "scope" of a declaration includes any annotations on that declaration, simply because the start position of the declaration includes them (the annotations are part of the declaration, not a separate prior thing).
> 
> Regarding exactly how "it's completely up to the particular warning": Since #26138, the `DiagnosticPosition` class now has a `getLintPosition()` property. This allows the caller to specify any arbitrary source code position at which to define which `@SuppressWarnings` annotations apply to the warning. Search for `withLintPosition()` to see a couple of uses of it.

The reason I ask is that I can probably see how it could be useful to emit a "suppression" warning from this:

    @SuppressWarnings("suppression")
    public class A { }

I'm not suggesting the PR should implement it, I'm just thinking aloud.

I realise that if it were to implement the annotation as non-self-referring, then there would need to be a way to suppress it too, however silly it may sound.

IIRC there's no way to apply a meta annotation on a _call site_. Even if `@SuppressWarnings` was a `@Repeatable` annotation, this would not have the desired effect:

    @SuppressWarnings("suppression")
    @SuppressWarnings("suppression")
    public void foo(String bar) { ...

Another option is to go one scope higher and put an annotation there:

    @SuppressWarnings("suppression")
    public class FooBar { ...
    
        @SuppressWarnings("suppression")
        public void foo(String bar) { ...

The problem is that you may not have a higher scope. Which sounds like a rare, uninteresting corner case.

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

PR Comment: https://git.openjdk.org/jdk/pull/25167#issuecomment-3325606585


More information about the serviceability-dev mailing list