From 2e5dcf9a95c7b56fc1f7559d53dbab683abc9dbb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 5 Oct 2017 21:04:25 +0200 Subject: [PATCH] [java] Fix NPE in NcssCount rule Parent could also be a enum or an annotation and not just a class/interface. --- .../ast/ASTClassOrInterfaceDeclaration.java | 2 +- .../lang/java/rule/codesize/xml/NcssCount.xml | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java index 9e09fe341c..f660683159 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java @@ -50,7 +50,7 @@ public class ASTClassOrInterfaceDeclaration extends AbstractJavaAccessTypeNode i public JavaQualifiedName getQualifiedName() { if (qualifiedName == null) { if (isNested()) { - ASTClassOrInterfaceDeclaration parent = this.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); + ASTAnyTypeDeclaration parent = this.getFirstParentOfType(ASTAnyTypeDeclaration.class); JavaQualifiedName parentQN = parent.getQualifiedName(); qualifiedName = JavaQualifiedName.ofNestedClass(parentQN, this.getImage()); return qualifiedName; diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NcssCount.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NcssCount.xml index ac88a3b9d4..236f191a8f 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NcssCount.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NcssCount.xml @@ -215,4 +215,34 @@ public class Foo { 0 + + + Nullpointer for getQualifiedName + 0 + +