A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5785 below:

[java] UnusedPrivateField doesn't play well with UnnecessaryWarningSuppression · Issue #5785 · pmd/pmd · GitHub

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>

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