Affects PMD Version: 7.10.0
Rule: UnusedPrivateMethod
Description:
When using Lombok val, the type of the local variable is lombok.val instead of the inferred correct type.
When such a variable is used in a method call, we don't find the correct method declaration due to the different types and report the called method as unused.
Workaround: Don't use val, use final var instead. Note: lombok val is a final local variable, while Java's var, is a non-final local variable.
Code Sample demonstrating the issue:
package sample;
import lombok.val;
class Foo {
public void method() {
val test = "a";
privateMethod(test);
}
private void privateMethod(String a) {
System.out.println(a);
}
}
Complete reproducer project: issue-5369-unusedprivatemethod.zip
Expected outcome:
PMD reports a violation at line 12, but that's wrong. That's a false positive.
Running PMD through: Maven
Affects PMD Version: 7.10.0
Rule: UnusedPrivateMethod
Description:
When using Lombok val, the type of the local variable is
lombok.valinstead of the inferred correct type.When such a variable is used in a method call, we don't find the correct method declaration due to the different types and report the called method as unused.
Workaround: Don't use
val, usefinal varinstead. Note: lombok val is a final local variable, while Java's var, is a non-final local variable.Code Sample demonstrating the issue:
Complete reproducer project: issue-5369-unusedprivatemethod.zip
Expected outcome:
PMD reports a violation at line 12, but that's wrong. That's a false positive.
Running PMD through: Maven