Skip to content

[java] UselessOverridingMethod doesn't play well with UnnecessarySuppressWarning #5804

Closed

Description

@adangel

Affects PMD Version: 7.14.0

Description:

By default, the rule UselessOverridingMethod doesn't report a violation, if there are other annotations present (except for Override).

But when SupressWarnings annotation is added, then the rule skips itself - because this is an annotation other than Override and it never reports a violation that gets suppressed...

Then UnnecessaryWarningSuppression reports, that the suppress warnings annotation is unnecessary...

By the way - the rule description should be improved. I had a hard time understanding what is happening - and double negation (ignoreAnnotation = false) is adding to the confusion...

Code Sample demonstrating the issue:

// src/BaseClass.java
class BaseClass {
  void method() {
    System.out.println("base class");
  }
}

// src/SubClass.java
class SubClass extends BaseClass {
    @Override
    @SuppressWarnings("PMD.UselessOverridingMethod")
    void method() {
        super.method();
    }
}

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. compile: javac -d bin src/*.java
  2. run pmd:
    $PMD_HOME/bin/pmd check --aux-classpath bin \
      --rulesets category/java/design.xml/UselessOverridingMethod,category/java/bestpractices.xml/UnnecessaryWarningSuppression \
      --dir src
  3. Result is: src/SubClass.java:3: UnnecessaryWarningSuppression: Unnecessary @SuppressWarnings annotation
  4. Remove the suppressWarnings annotation and rerun pmd
  5. Result is: src/SubClass.java:3: UselessOverridingMethod: Overriding method merely calls super

Running PMD through: CLI

Activity

  1. added
    a:bug
    on Jun 6, 2025
  2. added this to the 7.15.0 milestone on Jun 26, 2025
  3. added a commit that references this issue on Jun 26, 2025
    360e858
  4. added a commit that references this issue on Jun 26, 2025
    e5516da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions