quarkusio/quarkus · error · IllegalArgumentException
More than one active context object for the given scope: ${s
Error message
More than one active context object for the given scope: ${selected} ${context} What it means
Contexts.getActiveContext(scopeType) iterates all registered contexts for a scope and returns the single active one. CDI permits at most one active context per normal scope; if two are simultaneously active, ArC throws IllegalArgumentException naming both. This protects deterministic bean instance resolution for client proxies and injected references.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Contexts.java:118
SessionScoped.class);
}
}
InjectableContext getActiveContext(Class<? extends Annotation> scopeType) {
// Application/Singleton/Dependent context is always active and it's not possible to register a custom context for these scopes
if (ApplicationScoped.class.equals(scopeType)) {
return applicationContext;
} else if (Singleton.class.equals(scopeType)) {
return singletonContext;
} else if (Dependent.class.equals(scopeType)) {
return dependentContext;
}
List<InjectableContext> contextsForScope = getContexts(scopeType);
InjectableContext selected = null;
for (InjectableContext context : contextsForScope) {
if (context.isActive()) {
if (selected != null) {
throw new IllegalArgumentException(
"More than one active context object for the given scope: " + selected + " " + context);
}
selected = context;
}
}
return selected;
}
List<InjectableContext> getContexts(Class<? extends Annotation> scopeType) {
// Optimize for built-in scopes - this method is used internally during client proxy invocation
if (ApplicationScoped.class.equals(scopeType)) {
return applicationContextSingleton;
} else if (RequestScoped.class.equals(scopeType)) {
return requestContextSingleton;
} else if (Singleton.class.equals(scopeType)) {
return singletonContextSingleton;
} else if (Dependent.class.equals(scopeType)) {
return dependentContextSingleton;View on GitHub (pinned to e1c734241f)
Solutions
- Audit activation code (activate()/begin()) for the scope and remove nested or duplicate activations; check isActive() first.
- If you register a custom context, ensure its scope annotation is unique and not shared with a built-in scope.
- Ensure contexts are properly terminated in finally blocks so overlapping activations cannot linger.
- Check ArC/Quarkus version mismatches in your build that might load two copies of a context provider.
Example fix
// before
transactionContext.begin(); // may already be active in outer code
// after
if (!transactionContext.isActive()) {
transactionContext.begin();
}
try { /* work */ } finally { transactionContext.end(); } Defensive patterns
Strategy: validation
Validate before calling
long active = Arc.container().getContexts(MyScoped.class).stream()
.filter(InjectableContext::isActive).count();
if (active > 1) {
throw new IllegalStateException("MyScope must have at most one active context, found " + active);
} Type guard
static boolean hasSingleActiveContext(Class<? extends Annotation> scope) {
return Arc.container().getContexts(scope).stream()
.filter(InjectableContext::isActive).limit(2).count() <= 1;
} Try / catch
try {
return Arc.container().instance(MyBean.class).get();
} catch (IllegalArgumentException e) {
if (!e.getMessage().contains("More than one active context")) throw e;
// end the duplicate context or rethrow with diagnostics
} Prevention
- Guard all context activations with isActive() checks.
- Register custom contexts only under unique scope annotations.
- Use try/finally to guarantee context termination and prevent overlaps.
- Review portable extensions for duplicate addContext calls.
When it happens
Trigger: Accessing a bean (directly or via client proxy) while two InjectableContext instances registered for the same scope annotation report isActive() == true — e.g. nested activation of a custom scope, or a custom context whose scope collides with a built-in one.
Common situations: Custom context extensions (e.g. a thread/transaction-scoped context) activated on top of an already-active matching context; test frameworks that activate request/session contexts in setup code while the runtime also activated them; duplicate context registration in a portable extension.
Related errors
- More than one context object for the given scope: ${selected
- 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/fd8afdfeaa9b2c58.
Report an issue: GitHub.