Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 0b886d7

Browse files
committed
Bugfix for NPE when processing @efragment if android.app.Fragment not in classpath. See #3.
1 parent 6c9e7da commit 0b886d7

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/helper/AnnotationHelper.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public boolean isSubtype(TypeElement t1, TypeElement t2) {
122122
return isSubtype(t1.asType(), t2.asType());
123123
}
124124

125+
/**
126+
* This method may return null if the {@link TypeElement} cannot be found in
127+
* the processor classpath
128+
*/
125129
public TypeElement typeElementFromQualifiedName(String qualifiedName) {
126130
return processingEnv.getElementUtils().getTypeElement(qualifiedName);
127131
}
@@ -174,7 +178,7 @@ public boolean isAbstract(Element element) {
174178
public boolean isInterface(TypeElement element) {
175179
return element.getKind().isInterface();
176180
}
177-
181+
178182
public boolean isTopLevel(TypeElement element) {
179183
return element.getNestingKind() == NestingKind.TOP_LEVEL;
180184
}

‎AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/helper/ValidatorHelper.java‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,12 @@ public void extendsOneOfTypes(Element element, List<String> typeQualifiedNames,
658658
TypeMirror elementType = element.asType();
659659

660660
for (String typeQualifiedName : typeQualifiedNames) {
661-
TypeMirror expectedType = annotationHelper.typeElementFromQualifiedName(typeQualifiedName).asType();
662-
if (annotationHelper.isSubtype(elementType, expectedType)) {
663-
return;
661+
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeQualifiedName);
662+
if (typeElement != null) {
663+
TypeMirror expectedType = typeElement.asType();
664+
if (annotationHelper.isSubtype(elementType, expectedType)) {
665+
return;
666+
}
664667
}
665668
}
666669
valid.invalidate();
@@ -670,10 +673,13 @@ public void extendsOneOfTypes(Element element, List<String> typeQualifiedNames,
670673
public void extendsType(Element element, String typeQualifiedName, IsValid valid) {
671674
TypeMirror elementType = element.asType();
672675

673-
TypeMirror expectedType = annotationHelper.typeElementFromQualifiedName(typeQualifiedName).asType();
674-
if (!annotationHelper.isSubtype(elementType, expectedType)) {
675-
valid.invalidate();
676-
annotationHelper.printAnnotationError(element, "%s can only be used on an element that extends " + typeQualifiedName);
676+
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeQualifiedName);
677+
if (typeElement != null) {
678+
TypeMirror expectedType = typeElement.asType();
679+
if (!annotationHelper.isSubtype(elementType, expectedType)) {
680+
valid.invalidate();
681+
annotationHelper.printAnnotationError(element, "%s can only be used on an element that extends " + typeQualifiedName);
682+
}
677683
}
678684
}
679685

0 commit comments

Comments
 (0)