pmd: fix #1084 NPE at UselessStringValueOfRule.java:36
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
????? ??, 2013 - 5.0.5:
|
||||
|
||||
Fixed bug 991: AvoidSynchronizedAtMethodLevel for static methods
|
||||
Fixed bug 1084: NPE at UselessStringValueOfRule.java:36
|
||||
Fixed bug 1104: IdempotentOperation false positive
|
||||
Fixed bug 1111: False positive: Useless parentheses
|
||||
Fixed bug 1114: CPD - Tokenizer not initialized with requested properties
|
||||
|
@ -10,6 +10,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTReferenceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTType;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration;
|
||||
|
||||
public class UselessStringValueOfRule extends AbstractJavaRule {
|
||||
@ -33,11 +34,14 @@ public class UselessStringValueOfRule extends AbstractJavaRule {
|
||||
if (args != null) {
|
||||
ASTName arg = args.getFirstDescendantOfType(ASTName.class);
|
||||
if (arg != null) {
|
||||
ASTType argType = arg.getNameDeclaration().getNode().jjtGetParent().jjtGetParent().getFirstDescendantOfType(ASTType.class);
|
||||
if (argType != null
|
||||
&& argType.jjtGetChild(0) instanceof ASTReferenceType
|
||||
&& ((ASTReferenceType)argType.jjtGetChild(0)).isArray()) {
|
||||
return super.visit(node, data);
|
||||
NameDeclaration declaration = arg.getNameDeclaration();
|
||||
if (declaration != null) {
|
||||
ASTType argType = declaration.getNode().jjtGetParent().jjtGetParent().getFirstDescendantOfType(ASTType.class);
|
||||
if (argType != null
|
||||
&& argType.jjtGetChild(0) instanceof ASTReferenceType
|
||||
&& ((ASTReferenceType)argType.jjtGetChild(0)).isArray()) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,25 @@ class TestClass {
|
||||
String abc = "1" + String.valueOf(idFormat);
|
||||
System.out.println(abc); // Output 100000
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1084 NPE at UselessStringValueOfRule.java:36</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import android.os.Build;
|
||||
|
||||
public class Test {
|
||||
|
||||
public String test() {
|
||||
print(String.valueOf(Build.TIME));
|
||||
print(String.valueOf(Build.VERSION.SDK_INT));
|
||||
}
|
||||
|
||||
private void print(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user