merged from 4.2 branch: Fixed bug 2002722 - false + in UseStringBufferForStringAppends
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6335 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
1 parent
80bbfd5db1
commit
979a60dca1
3 files changed
+40
-1
No files matched your search
@@ -343,6 +343,7 @@ Fixed bug 1988829 - Violation reported without source file name (actually a fix
|
||||
Fixed bug 1989814 - false +: ConsecutiveLiteralAppends
|
||||
Fixed bug 1977230 - false positive: UselessOverridingMethod
|
||||
Fixed bug 1998185 - BeanMembersShouldSerialize vs @SuppressWarnings("serial")
|
||||
Fixed bug 2002722 - false + in UseStringBufferForStringAppends
|
||||
ruleset.dtd and ruleset_xml_schema.xsd added to jar file in rulesets directory
|
||||
bin and java14/bin scripts:
|
||||
retroweaver version was not correct in java14/bin scripts
|
||||
|
||||
+32
@@ -99,6 +99,38 @@ public class Foo{
|
||||
for (int i = 0; i < 10; i++){
|
||||
result = result + i;
|
||||
} }
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
false positive bug #2002722
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
String dtdColumnNames[] = null;
|
||||
String sortedDtdColumns[] = null;
|
||||
final int loop = 0;
|
||||
dtdColumnNames[loop] = dtdColumnNames[loop].trim ( );
|
||||
sortedDtdColumns[loop] = sortedDtdColumns[loop].trim ( );
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
false positive bug #2002722, different bug in comment section
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar2() {
|
||||
String foo ="foo";
|
||||
foo = mangleTheInput(foo);
|
||||
}
|
||||
String mangleTheInput(final String s) { return s;}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
+7
-1
@@ -1,6 +1,7 @@
|
||||
package net.sourceforge.pmd.lang.java.rule.optimizations;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentOperator;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
@@ -15,7 +16,7 @@ public class UseStringBufferForStringAppendsRule extends AbstractJavaRule {
|
||||
|
||||
@Override
|
||||
public Object visit(ASTVariableDeclaratorId node, Object data) {
|
||||
if (!TypeHelper.isA(node, String.class)) {
|
||||
if (!TypeHelper.isA(node, String.class) || node.isArray()) {
|
||||
return data;
|
||||
}
|
||||
Node parent = node.jjtGetParent().jjtGetParent();
|
||||
@@ -28,6 +29,11 @@ public class UseStringBufferForStringAppendsRule extends AbstractJavaRule {
|
||||
if (statement == null) {
|
||||
continue;
|
||||
}
|
||||
ASTArgumentList argList = name.getFirstParentOfType(ASTArgumentList.class);
|
||||
if (argList != null && argList.getFirstParentOfType(ASTStatementExpression.class) == statement) {
|
||||
// used in method call
|
||||
continue;
|
||||
}
|
||||
if (statement.jjtGetNumChildren() > 0 && statement.jjtGetChild(0).getClass().equals(ASTPrimaryExpression.class)) {
|
||||
ASTName astName = statement.jjtGetChild(0).getFirstDescendantOfType(ASTName.class);
|
||||
if(astName != null){
|
||||
|
||||
Reference in new issue
Block a user