Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tsmock opened this issue Jun 13, 2024 · 0 comments
Labels
a:false-positive PMD flags a piece of code that is not problematic

Comments

@tsmock
Copy link

tsmock commented Jun 13, 2024

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

@tsmock tsmock added the a:false-positive PMD flags a piece of code that is not problematic label Jun 13, 2024
@oowekyala oowekyala changed the title [java] UnnecessaryVarargsArrayCreation should not warn when a method is overridden [java] UnnecessaryVarargsArrayCreation should not warn when a method is overloaded Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

No branches or pull requests

1 participant