Affects PMD Version:
7.3.0
Rule: UnusedPrivateMethod
Description:
private method referenced by method reference operators not getting detected as used
this::mymethod
Code Sample demonstrating the issue:
package com.mytest; import jakarta.validation.ConstraintViolation; //imported from jakarta.validation:jakarta.validation-api:3.0.2 import java.util.List; import java.util.Set; public class UnusedPrivateMethodFalsePositive { //this does not trigger UnusedPrivateMethod private void doWork(List obj) { obj.toString(); } public void execute(Set<List<?>> listOfLists) { listOfLists.forEach(this::doWork); } //BUT this does??? //UnusedPrivateMethod - this as a false positive - but what is different? private void addValidationError(ConstraintViolation constraintViolation) { constraintViolation.toString(); } public void addValidationErrors(Set<ConstraintViolation<?>> constraintViolations) { constraintViolations.forEach(this::addValidationError); } }
Expected outcome:
It is not an unused private method
PMD reports a violation at line ..., but that's wrong. That's a false positive.
UnusedPrivateMethodFalsePositive.java:19: UnusedPrivateMethod: Avoid unused private methods such as 'addValidationError(ConstraintViolation)'.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Maven AND cli both report it
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4