Affects PMD Version:
7.14.0
Description:
Adding UnnecessaryWarningSuppression to a custom ruleset causes UnusedPrivateField to be reported as unnecessary. Removing the suppression, PMD reports the field is unused.
Exception Stacktrace:
No stack trace
Code references/examples
Java code:
https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/styling/ContrastEnhancementImpl.java#L70
The custom ruleset has:
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
Steps to reproduce:
Adding UnnecessaryWarningSuppression to a custom ruleset causes UnusedPrivateField to be reported as unnecessary. Removing the suppression, PMD reports the field is unused.
Running PMD through: Maven
Workaround
My guess is the issue arises because UnusedPrivateField, according to docs, ignores annotated private fields.
Indeed, changing the configuration as follows, resolves the issue, and UnnecessaryWarningSuppression no longer reports the suppression to be unnecessary:
<rule ref="category/java/bestpractices.xml/UnusedPrivateField">
<properties>
<property name="reportForAnnotations" value="java.lang.SuppressWarnings" />
</properties>
</rule>
Affects PMD Version:
7.14.0
Description:
Adding UnnecessaryWarningSuppression to a custom ruleset causes UnusedPrivateField to be reported as unnecessary. Removing the suppression, PMD reports the field is unused.
Exception Stacktrace:
No stack trace
Code references/examples
Java code:
https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/styling/ContrastEnhancementImpl.java#L70
The custom ruleset has:
Steps to reproduce:
Adding UnnecessaryWarningSuppression to a custom ruleset causes UnusedPrivateField to be reported as unnecessary. Removing the suppression, PMD reports the field is unused.
Running PMD through: Maven
Workaround
My guess is the issue arises because UnusedPrivateField, according to docs, ignores annotated private fields.
Indeed, changing the configuration as follows, resolves the issue, and UnnecessaryWarningSuppression no longer reports the suppression to be unnecessary: