[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:
Andreas Dangel
2017-10-05 21:04:25 +02:00
parent dd596f0aef
commit 2e5dcf9a95
2 changed files with 31 additions and 1 deletions

View File

@ -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;

View File

@ -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>