Skip to content

[java] UnusedPrivateMethod: False positive with raw type for generic method #6028

Closed

Description

@Pankraz76

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

Activity

  1. added
    a:false-positive
    on Aug 31, 2025
  2. UncleOwen commented on Aug 31, 2025

    @UncleOwen
    Member

    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.
  3. Pankraz76 commented on Aug 31, 2025

    @Pankraz76
    ContributorAuthor
    • You managed to fill in every single part wrong.

    its just the template, right?

    updated the test data

  4. UncleOwen commented on Aug 31, 2025

    @UncleOwen
    Member

    If you want unreadable issues, it's "just" the template. Otherwise, it's a helpful tool to structure information.

  5. Pankraz76 commented on Sep 1, 2025

    @Pankraz76
    ContributorAuthor

    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.

  6. zbynek commented on Sep 1, 2025

    @zbynek
    Contributor

    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.

  7. oowekyala commented on Sep 1, 2025

    @oowekyala
    Member

    Yes this looks like it's related to raw types. Maybe related to #5097

  8. 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, 2025
  9. added this to the 7.20.0 milestone on Dec 1, 2025
  10. added 2 commits that reference this issue on Dec 1, 2025
    5f318ea
    406043b
  11. 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
  12. added 2 commits that reference this issue on Dec 19, 2025
  13. added a commit that references this issue on Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions