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
This commit is contained in:
Ryan Gustafson
2008-06-10 20:58:24 +00:00
parent d9c6cb8b31
commit b287a5a73c
3 changed files with 20 additions and 1 deletions

View File

@ -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:

View File

@ -796,6 +796,23 @@ public class Foo {
sb.append('c');
return sb.toString();
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
44, Appending of not String additive expressions
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public void foo(int i) {
StringBuffer sb = new StringBuffer();
sb.append("Hello");
sb.append(i + 1);
sb.append(1 + i);
sb.append("World");
}
}
]]></code>
</test-code>

View File

@ -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;