forked from phoedos/pmd
#1401 False positive for StringBuilder.append called with constructor
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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:**
|
||||
|
Reference in New Issue
Block a user