pmd: fix NPE in ConstructorCallsOverridableMethodRule

This commit is contained in:
Andreas Dangel 2013-03-15 21:54:02 +01:00
parent 31f6b9af1a
commit c00ca9e44c

View File

@ -941,22 +941,24 @@ public final class ConstructorCallsOverridableMethodRule extends AbstractJavaRul
Node expression = argumentList.jjtGetChild(a);
ASTPrimaryPrefix arg = expression.getFirstDescendantOfType(ASTPrimaryPrefix.class);
String type = "<unknown>";
if (arg.jjtGetChild(0) instanceof ASTLiteral) {
ASTLiteral lit = (ASTLiteral) arg.jjtGetChild(0);
if (lit.isCharLiteral()) {
type = "char";
} else if (lit.isFloatLiteral()) {
type = "float";
} else if (lit.isIntLiteral()) {
type = "int";
} else if (lit.isStringLiteral()) {
type = "String";
} else if (lit.jjtGetChild(0) instanceof ASTBooleanLiteral) {
type = "boolean";
if (arg != null && arg.jjtGetNumChildren() > 0) {
if (arg.jjtGetChild(0) instanceof ASTLiteral) {
ASTLiteral lit = (ASTLiteral) arg.jjtGetChild(0);
if (lit.isCharLiteral()) {
type = "char";
} else if (lit.isFloatLiteral()) {
type = "float";
} else if (lit.isIntLiteral()) {
type = "int";
} else if (lit.isStringLiteral()) {
type = "String";
} else if (lit.jjtGetChild(0) instanceof ASTBooleanLiteral) {
type = "boolean";
}
} else if (arg.jjtGetChild(0) instanceof ASTName) {
// ASTName n = (ASTName)arg.jjtGetChild(0);
type = "ref";
}
} else if (arg.jjtGetChild(0) instanceof ASTName) {
// ASTName n = (ASTName)arg.jjtGetChild(0);
type = "ref";
}
argumentTypes.add(type);
}