GeezerVison is showing github.com — [java] UnusedPrivateMethod: False positive with raw type for generic method · Issue #6028 · pmd/pmd
[java] UnusedPrivateMethod: False positive with raw type for generic method #6028Description
Affects PMD Version: PMD 7.14.0
Rule: UnusedPrivateMethod
Description:
Code Sample demonstrating the issue:
import java.util.Collection;
public final class addAllImpl {
private static abstract class Multiset<K> extends Collection<K> { }
static <E> boolean addAllImpl(
Multiset<E> self, Collection<?> elements) {
return addAllImpl(self, (Multiset) elements);
}
private static <E> boolean addAllImpl(
Multiset<E> self, Multiset<E> elements) {
}
}
Expected outcome:
PMD reports a violation at line 10, but that's wrong. That's a false positive.
Running PMD through: maven-pmd-plugin 3.27.0 ActivityUncleOwen commented on Aug 31, 2025 Your issues are extremely difficult to read. Please
- Shorten your code samples so that they clearly demonstrate the issue.
- Use the provided template as it is intended. You managed to fill in every single part wrong.
Pankraz76 commented on Aug 31, 2025 ContributorAuthor More actions
- You managed to fill in every single part wrong.
its just the template, right?
updated the test data UncleOwen commented on Aug 31, 2025 If you want unreadable issues, it's "just" the template. Otherwise, it's a helpful tool to structure information. Pankraz76 commented on Sep 1, 2025 ContributorAuthor More actions yes you right, sorry.
Actually provided key information which is the recipe name and the test code thats all needed to reproduce.
Anything else is considered obsolete from my point of view. zbynek commented on Sep 1, 2025 The testcase can be simplified by removing the imports:
import java.util.Collection;
public final class addAllImpl {
private static abstract class Multiset<K> extends Collection<K> { }
static <E> boolean addAllImpl(
Multiset<E> self, Collection<?> elements) {
return addAllImpl(self, (Multiset) elements);
}
private static <E> boolean addAllImpl(
Multiset<E> self, Multiset<E> elements) {
}
}
Looks like overload resolution is not working well in a particular case involving generics. Reacted by Vincent Potuček and Andreas Dangel oowekyala commented on Sep 1, 2025 Yes this looks like it's related to raw types. Maybe related to #5097 Reacted by Vincent Potuček changed the title [-]Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'addAllImpl[/-] [+][java] UnusedPrivateMethod FP with raw type for generic method[/+] on Sep 1, 2025added 2 commits that reference this issue on Dec 1, 2025This issue will close once commit 5f318ea is merged into the 'main' branch.5f318ea This issue will close once commit 406043b is merged into the 'main' branch.406043b changed the title [-][java] UnusedPrivateMethod FP with raw type for generic method[/-] [+][java] UnusedPrivateMethod: False positive with raw type for generic method[/+] on Dec 19, 2025
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|