You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The private static method int foo(String s) is incorrectly recognized as an unused private method. The rule applies in the upper block of the code snippet, but not in the lower block - as method int foo2(String s) is not detected as false positive..
It is difficult for me to give a comprehensible explanation (which is also reflected in the title of the issue 😅), but it looks as if the rule applies incorrectly if the method is called via method reference and a custom object is used in the structure of the stream.
Hi and thanks for putting together a MWE. The reason this only occurs when you use a custom object is that PMD does not have access to compiled class information for this type. This is due to a mistake in the way PMD is configured, namely, you should run the compiler before PMD is run in Maven. You should change the phase of execution of PMD to verify to make sure the compiler runs before PMD: https://github.com/kesslerj/pmd-unused-private-method-issue-example-project/blob/main/pom.xml#L43
That being said, looking into this allowed me to improve a bit the logic we use to handle unresolved types. Even without configuring PMD properly, we should not complain anymore once #4989 is merged
I remember that we once moved it to the validate phase so that it would be executed together with Checkstyle right at the beginning. But that doesn't seem to be a technically clean solution.
Affects PMD Version: 7.1.0
Rule: UnusedPrivateMethod
Description:
The
private static
methodint foo(String s)
is incorrectly recognized as an unused private method. The rule applies in the upper block of the code snippet, but not in the lower block - as methodint foo2(String s)
is not detected as false positive..It is difficult for me to give a comprehensible explanation (which is also reflected in the title of the issue 😅), but it looks as if the rule applies incorrectly if the method is called via method reference and a custom object is used in the structure of the stream.
Code Sample demonstrating the issue:
Full code example can be found here: https://github.com/kesslerj/pmd-unused-private-method-issue-example-project .
Expected outcome:
PMD reports a violation at line 27, but that's wrong. That's a false positive.
Running PMD through: Maven
The text was updated successfully, but these errors were encountered: