#1330 AvoidReassigningParameters does not work with varargs
This commit is contained in:
@ -32,6 +32,7 @@ public class AvoidReassigningParametersRule extends AbstractJavaRule {
|
||||
if ((jocc.isOnLeftHandSide() || jocc.isSelfAssignment())
|
||||
&& jocc.getNameForWhichThisIsAQualifier() == null
|
||||
&& !jocc.useThisOrSuper()
|
||||
&& !decl.isVarargs()
|
||||
&& (!decl.isArray() || jocc.getLocation().jjtGetParent().jjtGetParent().jjtGetNumChildren() == 1)) {
|
||||
// not an array or no primary suffix to access the array
|
||||
// values
|
||||
|
@ -36,6 +36,12 @@ public class VariableNameDeclaration extends AbstractNameDeclaration implements
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVarargs() {
|
||||
ASTVariableDeclaratorId astVariableDeclaratorId = (ASTVariableDeclaratorId) node;
|
||||
ASTFormalParameter parameter = astVariableDeclaratorId.getFirstParentOfType(ASTFormalParameter.class);
|
||||
return parameter != null && parameter.isVarargs();
|
||||
}
|
||||
|
||||
public boolean isExceptionBlockParameter() {
|
||||
return ((ASTVariableDeclaratorId) node).isExceptionBlockParameter();
|
||||
}
|
||||
|
@ -234,6 +234,17 @@ public class PmdBug {
|
||||
public static void main(String[] args) {
|
||||
new PmdBug().foo("Hello world");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1330 AvoidReassigningParameters does not work with varargs</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class AvoidReassigningParameters {
|
||||
public void a(String... s) {
|
||||
s[0] = "";
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user