False positive in UnusedPrivateMethod with inner enum
A source code analyzer
Brought to you by:
adangel,
juansotuyo
I tried 5.2.1 today. I added the "auxclasspath" to the ant call.
The following method is flagged as unused because usages do not use plain objects for the "filterable" argument. For example some calls use a Part object and others use a UsageLink object.
private static void markAsFilteredOut(Object filterable, NavigationUnit navUnit) {
// do some stuff
}
This issue impacts more then just Object. I'm seeing the same behavior for methods where the call of the private method is using a subclass of the method's params.
Class B extends Class A
public void doSomething(B b) {
doSomethingPrivate(b);
}
private void doSomethingPrivate(A a) {
// PMD error here. If I manually cast the call to doSomethingPrivate((A)b) it doesn't generate PMD error.
}
Another example of this appear to be related to Enum's inside classes
public class Parent {
Enum A {...}
public void doSomething(B b) {
doSomethingPrivate(A.someEnum));
}
private void doSomethingPrivate(Parent.A a) {
// PMD error because it doesn't equate Parent.A as the same type as A.
}
}
Both of my examples used to work in 5.0.3
I couldn't reproduce neither of your cases.
I found an issue with configuring the classpath with ant (the nested enum A couldn't be loaded) - but using a jar file works.
Could you please checkout the attached zipfile bug-1276.zip and verify/adjust it to show your issues?
Thanks,
Andreas
It turns out, I should have read the documentation :) http://pmd.sourceforge.net/pmd-5.2.1/usage/ant-task.html
Using
auxclasspath
for the ant task solves the class loading issue with the nested enum A).Sorry, I missed the auxclasspath. It fixes my first case (class A/B), but didn't solve the enum problem. Attached is the fixed Parent example.
I did two things now:
Change the behavior of PMD if no auxclasspath is configured. In this case, there might be some false negatives (such as [#1226]) in this rule, but much less false positives.
The inner enum case was really a bug and not covered yet. This will be fixed with the next version.
Thanks for testing!
Related
Issues:
#1226