diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 7b7db2bcf5..aa2ce8cede 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -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 diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UselessStringValueOfRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UselessStringValueOfRule.java index debeb3e2a6..bf7c7ca8a0 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UselessStringValueOfRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UselessStringValueOfRule.java @@ -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); + } } } } diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/UselessStringValueOf.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/UselessStringValueOf.xml index 3c2db2d93e..d9ce973ddc 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/UselessStringValueOf.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strings/xml/UselessStringValueOf.xml @@ -91,6 +91,25 @@ class TestClass { String abc = "1" + String.valueOf(idFormat); System.out.println(abc); // Output 100000 } +} + ]]> + + + #1084 NPE at UselessStringValueOfRule.java:36 + 0 +