From 29c998417c4d95ea913d0be695f2e12a563b561e Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 21 Dec 2021 15:42:02 +0200 Subject: [PATCH] Disallow the use of @Inject in JAX-RS Application classes This did not work anyway, so it probably makes sense to disallow it completely Closes: #22277 --- .../io/quarkus/resteasy/common/spi/ResteasyDotNames.java | 4 ++++ .../common/deployment/ResteasyServerCommonProcessor.java | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/extensions/resteasy-classic/resteasy-common/spi/src/main/java/io/quarkus/resteasy/common/spi/ResteasyDotNames.java b/extensions/resteasy-classic/resteasy-common/spi/src/main/java/io/quarkus/resteasy/common/spi/ResteasyDotNames.java index c81d14b73fffd..d11919afc6d13 100644 --- a/extensions/resteasy-classic/resteasy-common/spi/src/main/java/io/quarkus/resteasy/common/spi/ResteasyDotNames.java +++ b/extensions/resteasy-classic/resteasy-common/spi/src/main/java/io/quarkus/resteasy/common/spi/ResteasyDotNames.java @@ -5,6 +5,8 @@ import java.util.Set; import java.util.function.Predicate; +import javax.inject.Inject; + import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.jandex.DotName; import org.jboss.jandex.FieldInfo; @@ -47,6 +49,8 @@ public final class ResteasyDotNames { .createSimple("org.jboss.resteasy.annotations.providers.multipart.PartType"); public static final DotName CONFIG_PROPERTY = DotName .createSimple(ConfigProperty.class.getName()); + public static final DotName CDI_INJECT = DotName + .createSimple(Inject.class.getName()); public static final DotName CDI_INSTANCE = DotName .createSimple(javax.enterprise.inject.Instance.class.getName()); public static final DotName JSON_IGNORE = DotName.createSimple("com.fasterxml.jackson.annotation.JsonIgnore"); diff --git a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java index d65a5a58c027e..697d937df4417 100755 --- a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java +++ b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java @@ -998,7 +998,12 @@ private static Set getAllowedClasses(IndexView index) { throw new RuntimeException("More than one Application class: " + applications); } selectedAppClass = applicationClassInfo; - // FIXME: yell if there's more than one + if (selectedAppClass.annotations().containsKey(ResteasyDotNames.CDI_INJECT)) { + throw new RuntimeException( + "Usage of '@Inject' is not allowed in 'javax.ws.rs.core.Application' classes. Offending class is '" + + selectedAppClass.name() + "'"); + } + String applicationClass = applicationClassInfo.name().toString(); try { Class appClass = Thread.currentThread().getContextClassLoader().loadClass(applicationClass);