forked from phoedos/pmd
#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>
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user