pmd: fix NPE in LooseCouplingRule

This commit is contained in:
Andreas Dangel 2013-04-05 17:29:53 +02:00
parent 4d7b4bb1bc
commit 0170a40dec
2 changed files with 2 additions and 3 deletions

View File

@ -39,7 +39,7 @@ public class LooseCouplingRule extends AbstractJavaRule {
private boolean methodHasOverride(Node node) {
ASTClassOrInterfaceBodyDeclaration method = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class);
if (method.jjtGetNumChildren() > 0 && method.jjtGetChild(0) instanceof ASTAnnotation) {
if (method != null && method.jjtGetNumChildren() > 0 && method.jjtGetChild(0) instanceof ASTAnnotation) {
ASTMarkerAnnotation marker = method.getFirstDescendantOfType(ASTMarkerAnnotation.class);
if (marker != null && marker.getFirstChildOfType(ASTName.class) != null) {
ASTName name = marker.getFirstChildOfType(ASTName.class);

View File

@ -37,11 +37,10 @@ public class LooseCoupling extends AbstractJavaRule {
private boolean methodHasOverride(Node node) {
ASTClassOrInterfaceBodyDeclaration method = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class);
if (method.jjtGetNumChildren() > 0 && method.jjtGetChild(0) instanceof ASTAnnotation) {
if (method != null && method.jjtGetNumChildren() > 0 && method.jjtGetChild(0) instanceof ASTAnnotation) {
ASTMarkerAnnotation marker = method.getFirstDescendantOfType(ASTMarkerAnnotation.class);
if (marker != null && marker.getFirstChildOfType(ASTName.class) != null) {
ASTName name = marker.getFirstChildOfType(ASTName.class);
System.out.println(name.getType());
if (name.getType() == Override.class) {
return true;
}