Could IC warn about unneccessary @SuppressWarning annotations?

Issue #2587 open
Aidan Harding created an issue

Sometimes, I’ll see code where someone has used something like

@SuppressWarnings('PMD.EmptyStatementBlock')

But the following block doesn’t actually have an empty statement block. Maybe the suppression was needed once and then the code has evolved so that it’s not needed any more.

Would it be possible for IC to warn about the annotation, saying that this suppression is unnecessary?

It’s one of those code-clutter issues like unused variables where IDE help would be beneficial, IMO.

Comments (2)

  1. Scott Wells repo owner
    • changed status to open

    I've thought about this one myself as the IDE already has Redundant suppression code inspection that seems language-agnostic. I'd been planning to investigate it and understand if there's anything I need to do to IC2's inspections to allow it to work.

    The issue with the PMD-specific inspection suppressions, though, is that they aren't processed by IC2 directly. They're processed by PMD itself when it runs, so I'd likely need to see if there's a way for PMD to provide a similar feature, effectively issuing a warning for an unnecessary suppression.

  2. Aidan Harding reporter

    Thanks, Scott. Native support in PMD would be a bit bigger piece of work than I thought this would be, but it would be a great contribution to PMD.

    It would be ugly, but I guess a “treat PMD like a black box” approach would be to run with --show-suppressed enabled and see if the results are different. Obviously, that’s twice the processing work, though.

  3. Log in to comment