Menu

#1257 False positive for UnusedPrivateMethod if only called with subclasses

PMD-5.2.1
wont-fix
None
PMD
3-Major
Bug
5.1.3
2014-11-03
2014-09-04
No

A false positive for UnusedPrivateMethod is reported if a method is defined using an interface or parent class and then called with a concrete class or sub class.

Example - this method is reported as unused
private void handleConfig(ConfigIfc config) {
config.doSomething();
}

public void someMethod() {
SomeConfigImpl config = new SomeConfigImpl(); // implements ConfigIfc
handleConfig(config); // use the method above
}

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-11-02

    For this to be working, you'll need to configure the auxclasspath, e.g.

    run.sh pmd -f text -d src -R java-unusedcode/UnusedPrivateMethod -auxclasspath bin
    

    You'll need to have your project compiled first. This commandline assumes, that the compiled class files are in the folder bin.

    Without the auxclasspath and the compiled sources, PMD is not able to detect that SomeConfigImpl is a ConfigIfc - and therefore raises this violation.

     
  • Andreas Dangel

    Andreas Dangel - 2014-11-02
    • status: open --> wont-fix
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-next
     

Log in to post a comment.