From b287a5a73c1021bd850b9f71486ca37d64c3aff3 Mon Sep 17 00:00:00 2001 From: Ryan Gustafson Date: Tue, 10 Jun 2008 20:58:24 +0000 Subject: [PATCH] Fixed bug 1989814 - false +: ConsecutiveLiteralAppends If the definitive type of an AdditiveExpression is known to be other than a String, don't complain. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6186 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../strings/xml/ConsecutiveLiteralAppends.xml | 17 +++++++++++++++++ .../strings/ConsecutiveLiteralAppends.java | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) 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;