Fixed bug 2645268 - ClassCastException in UselessOperationOnImmutable.getDeclaration

Problem was due to incorrect assumption about AST structure, when Annotations are present on a local declaration.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6879 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Ryan Gustafson
2009-03-01 09:57:16 +00:00
parent eeb8b10892
commit f7cefa4a7d
3 changed files with 17 additions and 1 deletions

View File

@ -3,6 +3,7 @@
Fixed bug 2590258 - NPE with nicerhtml output
Fixed bug 2317099 - False + in SimplifyCondition
Fixed bug 2606609 - False "UnusedImports" positive in package-info.java
Fixed bug 2645268 - ClassCastException in UselessOperationOnImmutable.getDeclaration
New rule:
StrictExceptions : AvoidCatchingGenericException

View File

@ -180,6 +180,21 @@ public BigDecimal myMethod(Object pObj)
//...
return cout;
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
2645268, ClassCastException using Annotation on Local Field
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
public void foo() {
@NotNull
BigDecimal bd = new BigDecimal(5);
bd.divideToIntegralValue(new BigDecimal(5));
}
}
]]></code>
</test-code>

View File

@ -86,7 +86,7 @@ public class UselessOperationOnImmutable extends AbstractJavaRule {
private ASTVariableDeclaratorId getDeclaration(ASTLocalVariableDeclaration node) {
ASTType type = node.getTypeNode();
if (mapClasses.keySet().contains(type.getTypeImage())) {
return (ASTVariableDeclaratorId) node.jjtGetChild(1).jjtGetChild(0);
return node.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
}
return null;
}