Skip to content

[java] UnusedPrivateMethod - false positive with JDK 17 #3899

@andygoossens

Description

@andygoossens

Affects PMD Version: 6.39.0, 6.44.0

Rule: UnusedPrivateMethod

Description: UnusedPrivateMethod incorrectly marks a used private method as unused on JDK 17. On JDK 11 it is working as expected.

Code Sample demonstrating the issue:

pmd/Parent.java

package pmd;

public interface Parent {

}

pmd/Child.java

package pmd;

public class Child implements Parent {

}

pmd/PmdTestCase.java

package pmd;

public class PmdTestCase {

  public void check() {
    Child child = new Child();

    checkChild(child);
    checkParent(child);
  }

  // OK
  private void checkChild(Child child) {
  }

  // This method results in "UnusedPrivateMethod: Avoid unused private methods such as 'checkParent(Parent)'"
  private void checkParent(Parent parent) { // false positive
  }
}

Expected outcome: First, I expected the same behaviour regardless which JDK version I use. Second, I expected that PMD would not have an issue with this code. That's a false positive.

Running PMD through: Gradle, version 7.4.2

Relevant Gradle config:

java {
  toolchain {
    languageVersion = JavaLanguageVersion.of(17) // but works with 11
  }
}

pmd {
  toolVersion = '6.44.0' // but also an issue with the default version (6.39.0)

  // ... my custom rule set ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions