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.
javac -d bin src/*.java
$PMD_HOME/bin/pmd check --aux-classpath bin \ --rulesets category/java/design.xml/UselessOverridingMethod,category/java/bestpractices.xml/UnnecessaryWarningSuppression \ --dir src
src/SubClass.java:3: UnnecessaryWarningSuppression: Unnecessary @SuppressWarnings annotation
src/SubClass.java:3: UselessOverridingMethod: Overriding method merely calls super
Running PMD through: CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4