Skip to content

Commit

Permalink
Merge pull request #17445 from geoand/#17441
Browse files Browse the repository at this point in the history
Fail at build time if @Inject is used in JAX-RS Application class
  • Loading branch information
gsmet authored May 25, 2021
2 parents 003d56f + 1c5b757 commit 862a3d4
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public static ApplicationScanningResult scanForApplicationClass(IndexView index,
throw new RuntimeException("More than one Application class: " + applications);
}
selectedAppClass = applicationClassInfo;
// FIXME: yell if there's more than one
if (appClassHasInject(selectedAppClass)) {
throw new RuntimeException("'@Inject' cannot be used with a '" + ResteasyReactiveDotNames.APPLICATION
+ "' class. Offending class is: '" + selectedAppClass.name() + "'");
}
String applicationClass = applicationClassInfo.name().toString();
try {
Class<?> appClass = Thread.currentThread().getContextClassLoader().loadClass(applicationClass);
Expand Down Expand Up @@ -104,6 +107,14 @@ public static ApplicationScanningResult scanForApplicationClass(IndexView index,
selectedAppClass, blocking);
}

private static boolean appClassHasInject(ClassInfo appClass) {
if (appClass.annotations() == null) {
return false;
}
List<AnnotationInstance> injectInstances = appClass.annotations().get(ResteasyReactiveDotNames.CDI_INJECT);
return (injectInstances != null) && !injectInstances.isEmpty();
}

public static ResourceScanningResult scanResources(
IndexView index) {
Collection<AnnotationInstance> paths = index.getAnnotations(ResteasyReactiveDotNames.PATH);
Expand Down

0 comments on commit 862a3d4

Please sign in to comment.