Menu

#792 False +: UnusedPrivateMethod and for-each loop

open
nobody
None
5
2012-10-07
2008-08-07
No

I'm using PMD 4.1 through maven-pmd-plugin version 2.4, but I can't see this problem mentioned in the bugfix list for PMD 4.2.

If a private method is used in a for-each loop, the UnusedPrivateMethod rule generates a false positive. Here's an example:


public class UnusedPrivateMethodFalsePositiveExample {

UnusedPrivateMethodFalsePositiveExample[] foos;

public void foo() {
for (UnusedPrivateMethodFalsePositiveExample foo : foos) {
foo.falsePositive();
}
}

private void falsePositive() {
}

}

UnusedPrivateMethod reports the method falsePositive() isn't used, but clearly it is in the for-each loop.

Discussion


Log in to post a comment.