Skip to content

Commit

Permalink
Fail at build time if @Inject is used in JAX-RS Application class
Browse files Browse the repository at this point in the history
Relates to: #17441
  • Loading branch information
geoand committed May 25, 2021
1 parent 950286b commit 1c5b757
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 1c5b757

Please sign in to comment.