Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow the use of @Inject in JAX-RS Application classes #22440

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -998,7 +998,12 @@ private static Set<String> getAllowedClasses(IndexView index) {
throw new RuntimeException("More than one Application class: " + applications);
}
selectedAppClass = applicationClassInfo;
// FIXME: yell if there's more than one
gastaldi marked this conversation as resolved.
Show resolved Hide resolved
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);