Skip to content

Commit ee13030

Browse files
tdurieuxmonperrus
authored andcommitted
fix: npe in getEnclosingType when getTypeDeclaration is null (#2033)
1 parent 098b159 commit ee13030

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/main/java/spoon/support/visitor/ClassTypingContext.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
*/
1717
package spoon.support.visitor;
1818

19-
import java.awt.event.HierarchyListener;
20-
import java.util.ArrayList;
21-
import java.util.Collections;
22-
import java.util.HashMap;
23-
import java.util.HashSet;
24-
import java.util.List;
25-
import java.util.Map;
26-
import java.util.Set;
27-
2819
import spoon.SpoonException;
2920
import spoon.reflect.declaration.CtConstructor;
3021
import spoon.reflect.declaration.CtElement;
@@ -44,6 +35,14 @@
4435
import spoon.reflect.visitor.filter.SuperInheritanceHierarchyFunction;
4536
import spoon.support.SpoonClassNotFoundException;
4637

38+
import java.util.ArrayList;
39+
import java.util.Collections;
40+
import java.util.HashMap;
41+
import java.util.HashSet;
42+
import java.util.List;
43+
import java.util.Map;
44+
import java.util.Set;
45+
4746
/**
4847
* Helper class created from type X or reference to X.
4948
* It provides access to actual type arguments
@@ -366,16 +365,18 @@ private CtType<?> getEnclosingType(CtType<?> type) {
366365
*/
367366
private CtTypeReference<?> getEnclosingType(CtTypeReference<?> typeRef) {
368367
CtType<?> type = typeRef.getTypeDeclaration();
369-
if (type.hasModifier(ModifierKind.STATIC)) {
370-
return null;
371-
}
372-
CtType<?> declType = type.getDeclaringType();
373-
if (declType == null) {
374-
return null;
375-
}
376-
if (declType.isInterface()) {
377-
//nested types of interfaces are static
378-
return null;
368+
if (type != null) {
369+
if (type.hasModifier(ModifierKind.STATIC)) {
370+
return null;
371+
}
372+
CtType<?> declType = type.getDeclaringType();
373+
if (declType == null) {
374+
return null;
375+
}
376+
if (declType.isInterface()) {
377+
//nested types of interfaces are static
378+
return null;
379+
}
379380
}
380381
return typeRef.getDeclaringType();
381382
}

0 commit comments

Comments
 (0)