Fix ClassCastException on CloneMethodMustImplementCloneable
- Java 8 code allows for things such as `class UnmodifiableList<T> implements @Readonly List<@Readonly T> {}` where not all token in the ASTImplementsList are ASTClassOrInterfaceType
This commit is contained in:

committed by
Andreas Dangel

parent
f4f2402661
commit
238f6b721b
@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.typeresolution.rules;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBlock;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBlockStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
@ -33,7 +34,13 @@ public class CloneMethodMustImplementCloneable extends AbstractJavaRule {
|
||||
ASTImplementsList impl = node.getFirstChildOfType(ASTImplementsList.class);
|
||||
if (impl != null && impl.jjtGetParent().equals(node)) {
|
||||
for (int ix = 0; ix < impl.jjtGetNumChildren(); ix++) {
|
||||
ASTClassOrInterfaceType type = (ASTClassOrInterfaceType) impl.jjtGetChild(ix);
|
||||
Node child = impl.jjtGetChild(ix);
|
||||
|
||||
if (child.getClass() != ASTClassOrInterfaceType.class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASTClassOrInterfaceType type = (ASTClassOrInterfaceType) child;
|
||||
if (type.getType() == null) {
|
||||
if ("Cloneable".equals(type.getImage())) {
|
||||
return data;
|
||||
|
Reference in New Issue
Block a user