diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt
index 04f9db7a2f..45b2938aae 100644
--- a/pmd/etc/changelog.txt
+++ b/pmd/etc/changelog.txt
@@ -7,6 +7,7 @@ Add C# support for CPD - thanks to Florian Bauer
Fix small bug in Rule Designer UI
Improve TooManyMethods rule - thanks to a patch from Riku Nykanen
Improve DoNotCallSystemExit - thanks to a patch from Steven Christou
+Fix false negative for UseArraysAsList when the array was passed as method parameter - thanks to Andy Throgmorton
New Rule:
Basic ruleset: DontCallThreadRun - thanks to Andy Throgmorton
diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UseArraysAsList.xml b/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UseArraysAsList.xml
index 0a2fa264ad..f088aa9274 100644
--- a/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UseArraysAsList.xml
+++ b/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UseArraysAsList.xml
@@ -8,11 +8,11 @@ failure case
@@ -25,11 +25,11 @@ adding first element repeatedly
@@ -42,11 +42,11 @@ inside conditional
10) { l.add(ints[1]);}
- }
+ Integer[] ints = new Integer(10);
+ List l= new ArrayList(10);
+ for (int i=0; i< 100; i++) {
+ if (y > 10) { l.add(ints[1]);}
+ }
}
}
]]>
@@ -59,11 +59,11 @@ adding new object
@@ -76,13 +76,31 @@ calling method
-
\ No newline at end of file
+
+ Integer array passed as argument
+ 1
+
+
+
diff --git a/pmd/rulesets/optimizations.xml b/pmd/rulesets/optimizations.xml
index f64d29caec..dad9cc5486 100644
--- a/pmd/rulesets/optimizations.xml
+++ b/pmd/rulesets/optimizations.xml
@@ -187,7 +187,7 @@ public class Foo {
]
//StatementExpression[
PrimaryExpression/PrimaryPrefix/Name[
- substring-before(@Image,'.add') = ancestor::MethodDeclaration//LocalVariableDeclaration[
+ substring-before(@Image,'.add') = ancestor::MethodDeclaration//LocalVariableDeclaration[
./Type//ClassOrInterfaceType[
@Image = 'Collection' or
@Image = 'List' or @Image='ArrayList'
@@ -202,8 +202,11 @@ public class Foo {
]
and
PrimaryExpression/PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name
- [@Image = ancestor::MethodDeclaration//LocalVariableDeclaration
- [@Array="true"]/VariableDeclarator/VariableDeclaratorId/@Image]
+ [
+ @Image = ancestor::MethodDeclaration//LocalVariableDeclaration[@Array="true"]/VariableDeclarator/VariableDeclaratorId/@Image
+ or
+ @Image = ancestor::MethodDeclaration//FormalParameter/VariableDeclaratorId/@Image
+ ]
/../..[count(.//PrimarySuffix)
=1]/PrimarySuffix/Expression/PrimaryExpression/PrimaryPrefix
/Name
diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml
index 9c40ce1117..b7fcfed358 100644
--- a/pmd/xdocs/credits.xml
+++ b/pmd/xdocs/credits.xml
@@ -57,7 +57,7 @@
- - Andy Throgmorton - New XPath getCommentOn function, new rule DontCallThreadRun
+ - Andy Throgmorton - New XPath getCommentOn function, new rule DontCallThreadRun, fix for rule UseArraysAsList
- Nicolas Dordet - Fixed an issue on CloseResource
- Juan Jesús GarcÃa de Soria - Rework CPD algorithm
- Sergey Pariev - Fixed an ugly ArrayIndexOutOfBoundsException in CPD for Ruby