forked from phoedos/pmd
[java] Fix NPE in NcssCount rule
Parent could also be a enum or an annotation and not just a class/interface.
This commit is contained in:
@ -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;
|
||||
|
@ -215,4 +215,34 @@ public class Foo {
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="complicated-method"/>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Nullpointer for getQualifiedName</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public enum EnumWithAnonymousInnerClass {
|
||||
A {
|
||||
@Override
|
||||
public void foo() {
|
||||
super.foo();
|
||||
}
|
||||
},
|
||||
B;
|
||||
|
||||
public void foo() {
|
||||
}
|
||||
|
||||
interface Inner {
|
||||
int get();
|
||||
}
|
||||
|
||||
public static final Inner VAL = new Inner() {
|
||||
@Override
|
||||
public int get() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user