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