Menu

#1278 UnusedPrivateMethod spurious warnings for methods called with subclasses of their arguments

PMD-5.2.2
obsolete
None
PMD
3-Major
Bug
5.2.1
2014-12-14
2014-11-07
Ross
No

Rule:
UnusedPrivateMethod

Rule set:
Unused Code

Generates the following incorrect warnings for the following code:

Avoid unused private methods such as 'badA(A)'
Avoid unused private methods such as 'badX(Exception)'

public class C {

    private void badA(A a) {}
    private void badX(Exception e) {}

    private void goodA(A a) {}
    private void goodN(A a) {}
    private void goodO(Object o) {}

    public void bad() {
        B b = null;
        badA(b);
        badA(new B());
        badX(new X());

        goodA(new A());
        goodN(null);
        goodO(new A());
    }
}

class A {}

class B extends A {}

class X extends Exception {}

Related

Issues: #1287

Discussion

  • Andreas Dangel

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

    Andreas Dangel - 2014-11-14

    I couldn't reproduce your problem.
    Are you using already the "auxclasspath" option? (e.g. for ant see http://pmd.sourceforge.net/pmd-5.2.1/usage/ant-task.html)
    How do you start pmd? (commandline, ant, ...)

    Could please check the attached test case in bug-1278.zip?

    Thanks,
    Andreas

     

    Last edit: Andreas Dangel 2014-11-14
  • Andreas Dangel

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

    Andreas Dangel - 2014-11-15

    I assume, this is just caused by missing auxclasspath option.

    While fixing [#1276], I've changed 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.

    So, I'm closing this issue as "obsolete".

     

    Related

    Issues: #1226
    Issues: #1276


    Last edit: Andreas Dangel 2014-11-15
  • Ross

    Ross - 2014-12-06

    Sorry, I missed the emails about your comments.

    I am using EasyPMD 6.0 in NetBeans, with a Java free-form project.

    Do you know how to set the auxclasspath for that? If not, I will ask the creator of EasyPMD.

    Thanks.

     
  • Andreas Dangel

    Andreas Dangel - 2014-12-14

    It looks like you can configure "Additional classpath" URLs for EasyPMD - which should configure the auxclasspath.

     

Log in to post a comment.