You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
Hi, I have encountered a false negative when PMD tried to detect UseStringBufferForStringAppends. Below is the test case for reproducing this false negative:
Code Sample demonstrating the issue:
publicvoidtestUseStringBufferForStringAppends() {
Stringa;
a = "foo";
a += " bar"; // Should report a warning here
}
Expected outcome:Warning
PMD should report a violation at line 4, but doesn't. This is a false-negative.
Running PMD through:[Maven]
The text was updated successfully, but these errors were encountered:
@adangel Hi Andreas, could you please help me check this issue? Thanks!
adangel
changed the title
A false negative from PMD official document
[java] UseStringBufferForStringAppends: Wrong example in documentation
Jul 1, 2021
the example we have on our documentation is too trivial. Exactly this case has been removed from detection with #1736 . If you create manually a StringBuilder to concatenate two strings, it will be slower - the java compiler optimizes this already for you. See also the comment at #1736.
Btw. the example is of course so trivial, that you would actually just write String a = "foo bar" instead of concatenating constant strings.
We probably should use a more complex example, like
Stringresult = "";
for (inti = 0; i < 10; i++) {
result += getStringFromSomeWhere(i);
}
This indeed should be written using a StringBuilder.
Affects PMD Version:
Rule:UseStringBufferForStringAppends
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_performance.html#usestringbufferforstringappends
Description:
Hi, I have encountered a false negative when PMD tried to detect UseStringBufferForStringAppends. Below is the test case for reproducing this false negative:
Code Sample demonstrating the issue:
Expected outcome:Warning
PMD should report a violation at line 4, but doesn't. This is a false-negative.
Running PMD through: [Maven]
The text was updated successfully, but these errors were encountered: