Menu

#1233 UnusedPrivateMethod: False positive : method called on returned object.

PMD-5.1.3
closed
None
PMD
3-Major
Bug
5.1.2
2014-08-31
2014-08-05
No

When calling a method on the returned object from a private method I get a false positive from PMD, but only if the called method takes parameters.

I have searched the existing issues, but could not see anyone adressing this exact problem.

Example:

~~~~~~~~~
import java.util.Locale;

public class Test {

public static void main(String args[]) {
    Test t = new Test();
    t.baz();
}

// Here we call both foo() and bar()
public void baz() {
    foo().toLowerCase(Locale.US);
    bar().toLowerCase();
}

private String foo() {
    return "Hello World";
}

private String bar() {
    return "Hello World";
}

}
~~~~~~~~

In the above example PMD will tell me that foo() is an unused private method, but bar() is accepted.

This might be known behaviour, but it was surprising to me.

Related

Issues: #1156

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-08-05
    • status: open --> closed
    • assigned_to: Andreas Dangel
     
  • Andreas Dangel

    Andreas Dangel - 2014-08-05

    Thanks for the bug report. This will be fixed with the next (5.1.3) version.

     

Log in to post a comment.