quarkusio/quarkus · error · IllegalStateException

Failed to register a context - built-in singleton context is

Error message

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

What it means

Same bootstrap guard as the application context: ArcContainerImpl rejects a custom context registered for @Singleton because the built-in singleton context is always active. Registration aborts with IllegalStateException before the container finishes booting.

Source

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

                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;
            }
            Class<?> rawType = Types.getRawType(type);
            if (rawType == null) {
                continue;
            }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Drop the custom Singleton context — the built-in one is always active
  2. Use the built-in singleton context's API (e.g. Arc.container().getContext(Singleton.class)) instead of registering a replacement
  3. Register custom contexts only for non-built-in scope annotations

Example fix

// before
builder.addContext(new MySingletonContext(Singleton.class));
// after
InjectableContext ctx = Arc.container().getContext(Singleton.class); // use built-in
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Registering an InjectableContext whose getScope() equals Singleton.class during container construction (via Components passed to Arc initialization).

Common situations: Custom embedded CDI setups or test frameworks providing their own singleton context; migration from other CDI implementations with explicit singleton context registration; copy-pasted context registration code.

Related errors


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