From 1c5b7575385ad48eeaa6de221899d4eeca04cf4a Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 25 May 2021 09:53:30 +0300 Subject: [PATCH] Fail at build time if @Inject is used in JAX-RS Application class Relates to: #17441 --- .../processor/scanning/ResteasyReactiveScanner.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java index 55b2e9c5a6d35..f75fe16974211 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java @@ -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); @@ -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 injectInstances = appClass.annotations().get(ResteasyReactiveDotNames.CDI_INJECT); + return (injectInstances != null) && !injectInstances.isEmpty(); + } + public static ResourceScanningResult scanResources( IndexView index) { Collection paths = index.getAnnotations(ResteasyReactiveDotNames.PATH);