UnusedCode/UnusedPrivateMethod False Alarm
A source code analyzer
Brought to you by:
adangel,
juansotuyo
Example that shows the bug:
Class 1:
public class Parent { public void parentMethod() {} }
Class 2:
public class Child extends Parent { public void childMethod() {} }
Class 3:
public class Client { public void clientMethod() { final Child c = new Child(); privateMethod1( c ); privateMethod2( c ); } private void privateMethod1( Parent p ) { p.parentMethod(); } private void privateMethod2( Child c ) { c.childMethod(); } }
Compiled with Java 6.
The problem is that "privateMethod1", the one invoked with a var of the Child
type but declared with the supertype, is flagged as "unused" (wrong). The method
privateMethod2, for which the types matched, is not flagged (correct).
Diff:
Thanks for the bug report.
I can reproduce your example with PMD 5.2.1 (without auxclasspath option) - but it doesn't show up anymore with PMD 5.2.2 nor with 5.2.3 (regardless of the auxclasspath option).
Can you verify, which version of PMD you are using?
Regards,
Andreas