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] New rule: UnnecessaryVarargsArrayCreation #3216

Closed
oowekyala opened this issue Apr 12, 2021 · 0 comments · Fixed by #4919
Closed

[java] New rule: UnnecessaryVarargsArrayCreation #3216

oowekyala opened this issue Apr 12, 2021 · 0 comments · Fixed by #4919
Labels
a:new-rule Proposal to add a new built-in rule
Milestone

Comments

@oowekyala
Copy link
Member

oowekyala commented Apr 12, 2021

Proposed Rule Name: UnnecessaryVarargsArrayCreation

Proposed Category: Code Style Best Practices

Description: This new rule would flag instances of code that explicitly creates an array when calling a varargs method. This is more heavy to read and could be simplified.

I think this new rule may only be written in pmd 7, because type resolution in pmd 6 does not expose information about the called method.

Code Sample:

List<String> strings = Arrays.asList(new String[] { "a", "b", }); // flagged by the rule
strings = Arrays.asList("a", "b"); // ok
Arrays.asList(someVariable) // ok

Possible Properties:

  • Should this rule be customizable via properties? No need
@oowekyala oowekyala added the a:new-rule Proposal to add a new built-in rule label Apr 12, 2021
@oowekyala oowekyala added this to the 7.0.0 milestone Apr 12, 2021
@oowekyala oowekyala added this to To do in PMD 7 Apr 12, 2021
@oowekyala oowekyala moved this from To do to Rule changes backlog in PMD 7 Apr 27, 2021
@oowekyala oowekyala mentioned this issue Apr 7, 2022
55 tasks
@adangel adangel modified the milestones: 7.0.0, 7.x Jan 23, 2023
@adangel adangel removed this from Rule changes backlog in PMD 7 Jan 23, 2023
@adangel adangel modified the milestones: 7.x, 7.1.0 Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants