Skip to content

Commit cc635e9

Browse files
authored
Add a more helpful error message when validator init fails (#111)
1 parent 31b323b commit cc635e9

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

eventbus-validator/src/main/java/net/minecraftforge/eventbus/validator/AbstractValidator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public void init(ProcessingEnvironment processingEnv) {
7171
this.processingEnv = processingEnv;
7272
var elements = processingEnv.getElementUtils();
7373
var types = processingEnv.getTypeUtils();
74-
EventTypes.inheritableEvent = elements.getTypeElement(InheritableEvent.class.getCanonicalName()).asType();
74+
try {
75+
EventTypes.inheritableEvent = elements.getTypeElement(InheritableEvent.class.getCanonicalName()).asType();
76+
} catch (NullPointerException|NoClassDefFoundError e) {
77+
initError(e);
78+
}
7579
EventTypes.recordEvent = elements.getTypeElement(RecordEvent.class.getCanonicalName()).asType();
7680
EventTypes.mutableEvent = elements.getTypeElement(MutableEvent.class.getCanonicalName()).asType();
7781
EventCharacteristics.cancellable = elements.getTypeElement(Cancellable.class.getCanonicalName()).asType();
@@ -84,4 +88,14 @@ public void init(ProcessingEnvironment processingEnv) {
8488
public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
8589
return List.of();
8690
}
91+
92+
private static void initError(Throwable e) {
93+
throw new IllegalStateException("""
94+
Failed to setup the EventBus validator annotation processor as unable to get the compiler type elements required for validating EventBus API usages.
95+
Possible solutions:
96+
- Ensure that EventBus is on the compile classpath/modulepath and that its version matches the validator version
97+
- Remove the EventBus validator annotation processor if you are not using EventBus in your project
98+
- Add `requires net.minecraftforge.eventbus` to your module-info.java if you are using Java modules
99+
""", e);
100+
}
87101
}

0 commit comments

Comments
 (0)