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] StringInstantiation: false negative when using method result #3848

Closed
ghost opened this issue Mar 16, 2022 · 1 comment
Closed

[java] StringInstantiation: false negative when using method result #3848

ghost opened this issue Mar 16, 2022 · 1 comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code in:type-resolution Affects the type resolution code
Milestone

Comments

@ghost
Copy link

ghost commented Mar 16, 2022

Affects PMD Version:6.42.0

Rule:StringInstantiation

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_performance.html#stringinstantiation

Description:

Hi, I found a false negative about the rule StringInstantiation. Please read the following code example. PMD should have reported a warning at line 5 because this line create a String object by new. Hence, I think this is a false negative. Thanks for your kind consideration.

Code Sample demonstrating the issue:

String getLiteral() {
    return "foo";
}
String foo() {
    return new String(getLiteral()); // should report a warning at this line
}

Expected outcome:Warning

PMD should report a violation at line 5, but doesn't. This is a false-negative.

Running PMD through: [Maven]

@ghost ghost added the a:false-negative PMD doesn't flag a problematic piece of code label Mar 16, 2022
@oowekyala oowekyala added in:type-resolution Affects the type resolution code needs-backport labels Mar 16, 2022
@jsotuyod
Copy link
Member

This is fixed in PMD 7.0.0-rc1. It won't be backported to PMD 6.

@oowekyala oowekyala added this to the 7.0.0 milestone Apr 24, 2023
@adangel adangel changed the title A false negative about the rule StringInstantiation [java] StringInstantiation: false negative when using method result Apr 25, 2023
adangel added a commit that referenced this issue Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code in:type-resolution Affects the type resolution code
Projects
None yet
Development

No branches or pull requests

2 participants