Skip to content

Commit

Permalink
Fix odd null pointer in module detection (#732)
Browse files Browse the repository at this point in the history
* fix odd nullpointer

* Update ExternalProvider.java
  • Loading branch information
SentryMan authored Nov 14, 2024
1 parent 7ee351a commit 76826a7
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.TreeSet;
import java.util.stream.Stream;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.ModuleElement;
Expand Down Expand Up @@ -295,8 +296,8 @@ private static Stream<TypeElement> injectExtensions() {

final var checkEnclosing =
allModules.stream()
.flatMap(m -> m.getEnclosedElements().stream())
.flatMap(p -> p.getEnclosedElements().stream())
.flatMap(ExternalProvider::getEnclosed)
.flatMap(ExternalProvider::getEnclosed)
.map(TypeElement.class::cast)
.filter(t -> t.getKind() == ElementKind.CLASS)
.filter(t -> t.getModifiers().contains(Modifier.PUBLIC))
Expand All @@ -311,6 +312,15 @@ private static Stream<TypeElement> injectExtensions() {
return Stream.concat(checkEnclosing, checkDirectives);
}

// when a project's module-info is misconfigured a certain way, getEnclosedElements throws an error
private static Stream<? extends Element> getEnclosed(Element e) {
try {
return e.getEnclosedElements().stream();
} catch (Exception ex) {
return Stream.of();
}
}

private static boolean isInjectExtension(ModuleElement.ProvidesDirective p) {
return "io.avaje.inject.spi.InjectExtension".equals(p.getService().getQualifiedName().toString());
}
Expand Down

0 comments on commit 76826a7

Please sign in to comment.