diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/ConsecutiveLiteralAppendsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/ConsecutiveLiteralAppendsRule.java index 07a8bcb68c..e07130c240 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/ConsecutiveLiteralAppendsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/ConsecutiveLiteralAppendsRule.java @@ -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; } } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveLiteralAppends.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveLiteralAppends.xml index 82c4bc31d3..c2143533c3 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveLiteralAppends.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/ConsecutiveLiteralAppends.xml @@ -1282,6 +1282,20 @@ public class ConsecutiveLiteralAppendsRuleTest { public void appendChar(final StringBuilder s) { // do nothing } +} + ]]> + + + #1401 False positive for StringBuilder.append called with constructor + 0 + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 892cef0f44..81e6e39677 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -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:**