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] StringToString doesn't trigger on string literals #3681

Closed
ghost opened this issue Dec 9, 2021 · 0 comments · Fixed by #4154
Closed

[java] StringToString doesn't trigger on string literals #3681

ghost opened this issue Dec 9, 2021 · 0 comments · Fixed by #4154
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@ghost
Copy link

ghost commented Dec 9, 2021

Affects PMD Version:6.41.0

Rule:StringToString

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

Description:
I found a false negative about the rule StringToString, please refer to the minimized sample below.

PMD should have reported a warning at line 3, but it does not. However, this is definitely a String object calls toString() method. So, I think this is a false negative.

Code Sample demonstrating the issue:

class Impl {
  String foo() {
    return "123".toString();
  }
}

Expected outcome:

PMD should report a violation at line 3, 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 Dec 9, 2021
@adangel adangel changed the title [java] Make StringToString can detect literal [java] StringToString doesn't trigger on string literals Oct 13, 2022
adangel added a commit to adangel/pmd that referenced this issue Oct 13, 2022
@adangel adangel added this to the 6.51.0 milestone Oct 13, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant