Skip to content

Commit f407585

Browse files
committed
Improve a little bit the message notification in case of errors if there is no elements
1 parent 50da2b9 commit f407585

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.net.URL;
2727
import java.util.Collections;
2828
import java.util.HashSet;
29+
import java.util.Iterator;
2930
import java.util.Map;
3031
import java.util.Properties;
3132
import java.util.Set;
@@ -651,8 +652,16 @@ private void handleException(Set<? extends TypeElement> annotations, RoundEnviro
651652
* eclipse.
652653
*/
653654

654-
Element element = roundEnv.getElementsAnnotatedWith(annotations.iterator().next()).iterator().next();
655-
messager.printMessage(Diagnostic.Kind.ERROR, errorMessage, element);
655+
Iterator<? extends TypeElement> iterator = annotations.iterator();
656+
if (iterator.hasNext()) {
657+
Element element = roundEnv.getElementsAnnotatedWith(iterator.next()).iterator().next();
658+
messager.printMessage(Diagnostic.Kind.ERROR, errorMessage, element);
659+
} else {
660+
// Sometime this is a total mess and javac could not even find one
661+
// element on which we could print the error. So we should just
662+
// throw an exception and let it go.
663+
throw new RuntimeException("An error occured and couldn't be printed on an element: " + errorMessage);
664+
}
656665
}
657666

658667
@Override

0 commit comments

Comments
 (0)