forked from phoedos/pmd
Fixing 1636420 - false + in StringToString
Code wasn't looking at the target method. There are no String[].toString's in PMD, running on other sources surfaced this git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4951 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -93,6 +93,24 @@ public class Foo {
|
||||
String foo[] = new String[0];
|
||||
foo.toString();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
Should only look at toString's of Arrays
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
protected static void parse_args(String argv[]){
|
||||
int len = argv.length;
|
||||
int i;
|
||||
for (i=0; i<len; i++){
|
||||
if (argv[i].equals("-package")){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -19,10 +19,11 @@ public class StringToStringRule extends AbstractRule {
|
||||
boolean isArray = node.isArray();
|
||||
for (Iterator i = node.getUsages().iterator(); i.hasNext();) {
|
||||
NameOccurrence occ = (NameOccurrence) i.next();
|
||||
if (occ.getNameForWhichThisIsAQualifier() != null) {
|
||||
if (!isArray && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("toString") != -1) {
|
||||
NameOccurrence qualifier = occ.getNameForWhichThisIsAQualifier();
|
||||
if (qualifier != null) {
|
||||
if (!isArray && qualifier.getImage().indexOf("toString") != -1) {
|
||||
addViolation(data, occ.getLocation());
|
||||
} else if (isArray && occ.getNameForWhichThisIsAQualifier().getLocation() != null && !ASTName.class.equals(occ.getNameForWhichThisIsAQualifier().getLocation().getClass())) {
|
||||
} else if (isArray && qualifier.getLocation() != null && !ASTName.class.equals(qualifier.getLocation().getClass()) && qualifier.getImage().equals("toString")) {
|
||||
addViolation(data, occ.getLocation());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user