quarkusio/quarkus · error · IllegalArgumentException
More than one context object for the given scope: ${selected
Error message
More than one context object for the given scope: ${selectedContext} ${context} What it means
ClientProxies.getDelegate() resolves a scope's client proxy target by asking each registered InjectableContext for that scope to return the instance if active. If two contexts for the same scope are both active AND both return a value, ArC cannot pick one deterministically and throws IllegalArgumentException naming both contexts. CDI allows at most one active context per normal scope.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ClientProxies.java:48
T result = context.getIfActive(bean, ClientProxies::newCreationalContext);
if (result == null) {
throw notActive(bean);
}
return result;
}
public static <T> T getDelegate(InjectableBean<T> bean) {
List<InjectableContext> contexts = Arc.requireContainer().getContexts(bean.getScope());
T result = null;
if (contexts.size() == 1) {
result = contexts.get(0).getIfActive(bean, ClientProxies::newCreationalContext);
} else {
InjectableContext selectedContext = null;
for (int i = 0; i < contexts.size(); i++) {
InjectableContext context = contexts.get(i);
if (result != null) {
if (context.isActive()) {
throw new IllegalArgumentException(
"More than one context object for the given scope: " + selectedContext + " " + context);
}
} else {
result = context.getIfActive(bean, ClientProxies::newCreationalContext);
if (result != null) {
selectedContext = context;
}
}
}
}
if (result == null) {
throw notActive(bean);
}
return result;
}
private static ContextNotActiveException notActive(InjectableBean<?> bean) {
String msg = String.format(View on GitHub (pinned to e1c734241f)
Solutions
- Find code that activates the scope twice (e.g. RequestContext.activate() in both a filter and a test harness) and remove the duplicate activation.
- If you register custom contexts, verify no custom context's scope overlaps a built-in active context for the same scope annotation.
- Terminate contexts properly (try/finally with terminate/deactivate) so stale active contexts don't coexist.
Example fix
// before
requestContext.activate(); // also started by the test filter -> two active contexts
// after
if (!Arc.container().requestContext().isActive()) {
Arc.container().requestContext().activate();
} Defensive patterns
Strategy: validation
Validate before calling
long active = Arc.container().getActiveContexts(MyScoped.class).stream() // or per-impl equivalents
.filter(InjectableContext::isActive).count();
if (active > 1) throw new IllegalStateException("scope activated more than once"); Type guard
static boolean isSingleActiveScope(Class<? extends Annotation> scope) {
long n = Arc.container().getContexts(scope).stream()
.filter(InjectableContext::isActive).count();
return n <= 1;
} Try / catch
try {
myScopedBean.doWork();
} catch (IllegalArgumentException e) {
if (!e.getMessage().contains("More than one context object")) throw e;
// deactivate duplicate context or fail fast with a clear message
} Prevention
- Always check isActive() before activating a context.
- Terminate contexts in finally blocks to avoid lingering activations.
- Give custom contexts their own scope annotation; never reuse built-in scopes.
- Avoid activating the same scope in both test harness and production filters.
When it happens
Trigger: Calling a method on a client proxy (normal-scoped bean) when two context objects registered for the same scope annotation are simultaneously active and each yields an instance (e.g. a request context registered twice, or a custom context overlapping a built-in one).
Common situations: Custom @ActivatedScope/@RequestScoped-like context implementations registered via servlet/request filters that start a second context while the built-in one is active; testing harnesses that start contexts multiple times; extension bugs double-registering a context.
Related errors
- More than one active context object for the given scope: ${s
- Producer method return type is a parameterized type with a t
- Unsupported injection point target: <injectionPoint>
- Not possible to define the scope %s for the REST client %s
- Resource classes that use field injection for REST parameter
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/90f1650d8a46a2ac.
Report an issue: GitHub.