Skip to content

[java] UnnecessaryVarargsArrayCreation should not warn when a method is overloaded #5069

Closed

Description

@tsmock

Affects PMD Version: 7.2.0

Rule: UnnecessaryVarargsArrayCreation

Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#unnecessaryvarargsarraycreation

Description:

Code Sample demonstrating the issue:

public class Test {
  public Test() {
    this(new String[] {"prefix"});
  }
  public Test(String otherPrefix) {
    this("prefix", otherPrefix);
  }
  private Test(String... prefixes) {
    for (String str : prefixes) {
      System.out.println(str);
    }
  }
}

Expected outcome:

PMD reports a violation at line 3, but that's wrong. That's a false positive.

[INFO] PMD version: 7.2.0
[INFO] PMD Failure: Test:3 Rule:UnnecessaryVarargsArrayCreation Priority:3 Unnecessary explicit array creation for varargs method call.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]: Maven

Activity

  1. added
    a:false-positive
    on Jun 13, 2024
  2. changed the title [-][java] UnnecessaryVarargsArrayCreation should not warn when a method is overridden[/-] [+][java] UnnecessaryVarargsArrayCreation should not warn when a method is overloaded[/+] on Jun 13, 2024
  3. UncleOwen commented on Sep 25, 2026

    @UncleOwen
    Member
    $ pmd-7.26.0 check -d Test.java -R category/java/bestpractices.xml/UnnecessaryVarargsArrayCreation --no-progress --no-cache
    Test.java:3:    UnnecessaryVarargsArrayCreation:        Unnecessary explicit array creation for varargs method call
    $ pmd-7.27.0 check -d Test.java -R category/java/bestpractices.xml/UnnecessaryVarargsArrayCreation --no-progress --no-cache
    [INFO] Found no violations.
    

    Looks like this was fixed with #6949.

  4. added this to the 7.27.0 milestone on Sep 25, 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