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/branches/pmd/4.3.x@7400 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse
2011-10-13 15:54:39 +00:00
parent b60d442777
commit 14cc641316
4 changed files with 52 additions and 30 deletions

View File

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

View File

@ -82,6 +82,24 @@ public class Bar {
l.add(String.valueOf(i));
}
}
}
]]></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>

View File

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

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>