quarkusio/quarkus · error · IllegalStateException

Failed to register a context - built-in application context

Error message

Failed to register a context - built-in application context is always active: " + context

What it means

During ArcContainerImpl construction, registering a custom context whose scope is @ApplicationScoped is rejected because the built-in application context is always active and cannot be overridden. This is a container bootstrap guard against duplicate context registration.

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java:229

                notifierOrNull(Set.of(Destroyed.Literal.REQUEST, Any.Literal.INSTANCE)),
                requestContextInstances != null ? requestContextInstances : ComputingCacheContextInstances::new);
        SessionContext sessionContext = new SessionContext(this.currentContextFactory.create(SessionScoped.class),
                notifierOrNull(Set.of(Initialized.Literal.SESSION, Any.Literal.INSTANCE)),
                notifierOrNull(Set.of(BeforeDestroyed.Literal.SESSION, Any.Literal.INSTANCE)),
                notifierOrNull(Set.of(Destroyed.Literal.SESSION, Any.Literal.INSTANCE)), ComputingCacheContextInstances::new);

        Contexts.Builder contextsBuilder = new Contexts.Builder(
                requestContext,
                sessionContext,
                applicationContext,
                new SingletonContext(),
                new DependentContext());

        // Add custom contexts
        for (Components c : components) {
            for (InjectableContext context : c.getContexts()) {
                if (ApplicationScoped.class.equals(context.getScope())) {
                    throw new IllegalStateException(
                            "Failed to register a context - built-in application context is always active: " + context);
                }
                if (Singleton.class.equals(context.getScope())) {
                    throw new IllegalStateException(
                            "Failed to register a context - built-in singleton context is always active: " + context);
                }
                contextsBuilder.putContext(context);
            }
        }

        this.contexts = contextsBuilder.build();
    }

    static void precomputeBeanRawTypes(Map<String, Set<InjectableBean<?>>> map, InjectableBean<?> bean) {
        for (Type type : bean.getTypes()) {
            if (Object.class.equals(type)) {
                continue;
            }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove the custom ApplicationScoped context registration — rely on the always-active built-in one
  2. If a custom lifecycle is needed, register the context under a different scope annotation
  3. Upgrade custom context code to extend/wrap existing behavior instead of replacing the built-in context

Example fix

// before
builder.addContext(new MyApplicationContext(ApplicationScoped.class));
// after
@Singleton // or a custom scope annotation
class MyContext { } // use built-in application context instead
Defensive patterns

Strategy: validation

Validate before calling

if (ApplicationScoped.class.equals(myContext.getScope())) throw new IllegalArgumentException("use built-in application context");

Type guard

boolean isBuiltInScope = ApplicationScoped.class.equals(ctx.getScope()) || Singleton.class.equals(ctx.getScope());

Prevention

When it happens

Trigger: Providing an InjectableContext for ApplicationScoped.class via SyntheticComponents/Components during Arc.container() initialization — e.g. custom @Vetoed context providers or testing frameworks registering their own application context.

Common situations: Custom test harnesses or embedded setups that try to replace the application context; ported code from other CDI containers where overriding contexts was allowed; plugin systems registering contexts programmatically.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/ad8c297dd5bcf6e2. Report an issue: GitHub.