diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index b8b6ee5532..14047068d9 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -3,6 +3,7 @@ Fixes for exclude-pattern Updates to RuleChain to honor RuleSet exclude-pattern Fixed bug 1988829 - Violation reported without source file name (actually a fix to ConsecutiveLiteralAppends) +Fixed bug 1989814 - false +: ConsecutiveLiteralAppends May 20, 2008 - 4.2.2: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/strings/xml/ConsecutiveLiteralAppends.xml b/pmd/regress/test/net/sourceforge/pmd/rules/strings/xml/ConsecutiveLiteralAppends.xml index 85702f5ba5..c6b8052bb0 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/strings/xml/ConsecutiveLiteralAppends.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/strings/xml/ConsecutiveLiteralAppends.xml @@ -796,6 +796,23 @@ public class Foo { sb.append('c'); return sb.toString(); } +} + ]]> + + + + 0 + diff --git a/pmd/src/net/sourceforge/pmd/rules/strings/ConsecutiveLiteralAppends.java b/pmd/src/net/sourceforge/pmd/rules/strings/ConsecutiveLiteralAppends.java index 7784881ae0..9c11f7a2d1 100644 --- a/pmd/src/net/sourceforge/pmd/rules/strings/ConsecutiveLiteralAppends.java +++ b/pmd/src/net/sourceforge/pmd/rules/strings/ConsecutiveLiteralAppends.java @@ -179,7 +179,8 @@ public class ConsecutiveLiteralAppends extends AbstractRule { private int processAdditive(Object data, int concurrentCount, SimpleNode sn, SimpleNode rootNode) { ASTAdditiveExpression additive = sn.getFirstChildOfType(ASTAdditiveExpression.class); - if (additive == null) { + // The additive expression must of be type String to count + if (additive == null || (additive.getType() != null && !TypeHelper.isA(additive, String.class))) { return 0; } int count = concurrentCount;