Skip to content

[java] UnnecessaryVarargsArrayCreation: add regression tests for #5069 - #7103

Merged
UncleOwen merged 1 commit into
pmd:mainfrom
Eljees:fix/5069-varargs-ctor-regression-test
Sep 25, 2026
Merged

UncleOwen merged 1 commit into
pmd:mainfrom
Eljees:fix/5069-varargs-ctor-regression-test

Conversation

@Eljees

@Eljees Eljees commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

#5069 reports that UnnecessaryVarargsArrayCreation flags this(new String[] {"prefix"}) in a constructor, although this("prefix") would select the Test(String) constructor instead of the varargs one.

The overload check added in #6949 (for #6611) already handles this: for a constructor it compares against all constructors of the class, and an explicit constructor invocation goes through the same path. So #5069 is fixed on main, but nothing pins it, and the issue is still open.

This adds two test cases to UnnecessaryVarargsArrayCreation.xml:

mvn -pl pmd-java -am -Dtest=UnnecessaryVarargsArrayCreationTest test: 10 tests, 0 failures.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

…5069

The overload check added for pmd#6611 also covers the explicit constructor
invocation from pmd#5069. Pin that case, and the counterpart without a
competing constructor, which must still be reported.
@pmd-actions-helper

Copy link
Copy Markdown
Contributor

Documentation Preview

No relevant source code has been changed, pmdtester skipped.

(comment created at 2026-09-24 02:12:40+00:00 for e09458d)

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@UncleOwen
UncleOwen merged commit a2a7952 into pmd:main Sep 25, 2026
12 checks passed
@UncleOwen UncleOwen added this to the 7.29.0 milestone Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants