@ -19,6 +19,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTStatementExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
@ -105,9 +106,12 @@ public class ArrayIsStoredDirectlyRule extends AbstractSunSecureRule {
|
||||
final ASTVariableDeclaratorId vid = parameter.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
|
||||
final String varName = vid.getImage();
|
||||
for (ASTBlockStatement b : bs) {
|
||||
if (b.hasDescendantOfType(ASTAssignmentOperator.class)) {
|
||||
if (b.getChild(0) instanceof ASTStatement && b.getChild(0).getChild(0) instanceof ASTStatementExpression) {
|
||||
final ASTStatementExpression se = b.getFirstDescendantOfType(ASTStatementExpression.class);
|
||||
if (se == null || !(se.getChild(0) instanceof ASTPrimaryExpression)) {
|
||||
if (se == null
|
||||
|| se.getNumChildren() < 2
|
||||
|| !(se.getChild(0) instanceof ASTPrimaryExpression)
|
||||
|| !(se.getChild(1) instanceof ASTAssignmentOperator)) {
|
||||
continue;
|
||||
}
|
||||
String assignedVar = getExpressionVarName(se);
|
||||
|
@ -269,4 +269,22 @@ public class Foo {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[java] ArrayIsStoredDirectly reports duplicated violation #3879</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>5</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
public class ExampleAISD {
|
||||
|
||||
public String[] strs;
|
||||
|
||||
public void func(String[] strs, boolean flag) { // line 5
|
||||
if (flag) {
|
||||
this.strs = strs; // line 7
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user