#1330 AvoidReassigningParameters does not work with varargs

This commit is contained in:
Andreas Dangel
2015-05-15 20:24:06 +02:00
parent cc43e6f8be
commit 357f206102
4 changed files with 19 additions and 0 deletions

View File

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

View File

@ -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();
}

View File

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

View File

@ -12,6 +12,7 @@
**Bugfixes:**
* [#1330](https://sourceforge.net/p/pmd/bugs/1330/): AvoidReassigningParameters does not work with varargs
* [#1335](https://sourceforge.net/p/pmd/bugs/1335/): GuardLogStatementJavaUtil should not apply to SLF4J Logger
* [#1342](https://sourceforge.net/p/pmd/bugs/1342/): UseConcurrentHashMap false positive (with documentation example)
* [#1343](https://sourceforge.net/p/pmd/bugs/1343/): MethodNamingConventions for overrided methods