#1401 False positive for StringBuilder.append called with constructor

This commit is contained in:
Andreas Dangel
2015-09-05 12:10:38 +02:00
parent bd83821dd9
commit 58292bfc38
3 changed files with 20 additions and 0 deletions

View File

@ -213,6 +213,11 @@ public class ConsecutiveLiteralAppendsRule extends AbstractJavaRule {
ASTLiteral literal = suffix.getFirstDescendantOfType(ASTLiteral.class);
if (literal != null && literal.isStringLiteral()) {
result++;
} else {
// if it was not a String literal that was appended, then we don't
// have a consecutive literal string append anymore and we can skip
// checking the remainder of the initializer
break;
}
}
}

View File

@ -1282,6 +1282,20 @@ public class ConsecutiveLiteralAppendsRuleTest {
public void appendChar(final StringBuilder s) {
// do nothing
}
}
]]></code>
</test-code>
<test-code>
<description>#1401 False positive for StringBuilder.append called with constructor</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public String foo(final String value)
{
StringBuilder s = new StringBuilder("start:").append(value).append(":end");
return s.toString();
}
}
]]></code>
</test-code>

View File

@ -15,6 +15,7 @@
* [#1370](https://sourceforge.net/p/pmd/bugs/1370/): ConsecutiveAppendsShouldReuse not detected properly on StringBuffer
* [#1371](https://sourceforge.net/p/pmd/bugs/1371/): InsufficientStringBufferDeclaration not detected properly on StringBuffer
* [#1384](https://sourceforge.net/p/pmd/bugs/1384/): NullPointerException in ConsecutiveLiteralAppendsRule
* [#1401](https://sourceforge.net/p/pmd/bugs/1401/): False positive for StringBuilder.append called with constructor
* [#1402](https://sourceforge.net/p/pmd/bugs/1402/): Windows-Only: File exclusions are not case insensitive
**API Changes:**