#1276 False positive in UnusedPrivateMethod with inner enum

PMD-5.2.2
closed
None
PMD
3-Major
Bug
5.2.1
2014-12-03
2014-11-04
No

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
}

Related

Issues: #1278
Issues: #1286
Issues: #1287

Discussion

  • szetheli

    szetheli - 2014-11-12

    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.
    }

     
  • szetheli

    szetheli - 2014-11-12

    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

     
  • Andreas Dangel

    Andreas Dangel - 2014-11-14

    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

     
  • Andreas Dangel

    Andreas Dangel - 2014-11-14
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     
  • szetheli

    szetheli - 2014-11-14

    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.

     
  • Andreas Dangel

    Andreas Dangel - 2014-11-15
    • summary: False positive in UnusedPrivateMethod when method arg is Object and not called with plain Object --> False positive in UnusedPrivateMethod with inner enum
     
  • Andreas Dangel

    Andreas Dangel - 2014-11-15

    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

  • Andreas Dangel

    Andreas Dangel - 2014-11-15
    • status: more-info-needed --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks