Applied patch 2822173: Fix false negative for UseArraysAsList when the array was passed as method parameter. Thanks to Andy Throgmorton.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7393 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Andreas Dangel committed 2011-10-09 10:57:48 +00:00
1 parent 7484fd60db
commit 05cb5bcbbe
4 files changed
+26 -4

No files matched your search

+1
View File
@@ -363,6 +363,7 @@ AssignmentInOperand enhanced to catch assignment in 'for' condition, as well as
Fix false positive on CastExpressions for UselessParentheses
Fix false positive where StringBuffer.setLength(0) was using default constructor size of 16, instead of actual constructor size.
Fix false negative for non-primitive types for VariableNamingConventions, also expanded scope to local and method/constructors, and enhanced customization options to choose between members/locals/parameters (all checked by default)
Fix false negative for UseArraysAsList when the array was passed as method parameter - thanks to Andy Throgmorton
Improve TooManyMethods rule - thanks to a patch from Riku Nykanen
Improve DoNotCallSystemExit - thanks to a patch from Steven Christou
Correct -benchmark reporting of Rule visits via the RuleChain
@@ -85,4 +85,22 @@ public class Bar {
}
]]></code>
</test-code>
<test-code>
<description>Integer array passed as argument</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Test {
public void foo(Integer[] ints) {
// could just use Arrays.asList(ints)
List l = new ArrayList(10);
for (int i=0; i< 100; i++) {
l.add(ints[i]);
}
for (int i=0; i< 100; i++) {
l.add(a[i].toString()); // won't trigger the rule
}
}
}
]]></code>
</test-code>
</test-data>
+6 -3
View File
@@ -198,7 +198,7 @@ an array of objects. It is faster than executing a loop to copy all the elements
]
//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'
@@ -213,8 +213,11 @@ an array of objects. It is faster than executing a loop to copy all the elements
]
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
+1 -1
View File
@@ -57,7 +57,7 @@
</subsection>
<subsection name="Contributors">
<ul>
<li>Andy Throgmorton - New XPath getCommentOn function, new rule DontCallThreadRun</li>
<li>Andy Throgmorton - New XPath getCommentOn function, new rule DontCallThreadRun, fix for rule UseArraysAsList</li>
<li>Nicolas Dordet - Fixed an issue on CloseResource</li>
<li>Juan Jesús García de Soria - Rework CPD algorithm</li>
<li>Sergey Pariev - Fixed an ugly ArrayIndexOutOfBoundsException in CPD for Ruby</li>