{"record":{"id":"e7d28f4fa6d0be66","repo":"quarkusio/quarkus","slug":"failed-to-register-a-context-built-in-singleton","errorCode":null,"errorMessage":"Failed to register a context - built-in singleton context is always active: \" + context","messagePattern":"Failed to register a context - built-in singleton context is always active: \" \\+ context","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java","lineNumber":233,"sourceCode":"                notifierOrNull(Set.of(BeforeDestroyed.Literal.SESSION, Any.Literal.INSTANCE)),\n                notifierOrNull(Set.of(Destroyed.Literal.SESSION, Any.Literal.INSTANCE)), ComputingCacheContextInstances::new);\n\n        Contexts.Builder contextsBuilder = new Contexts.Builder(\n                requestContext,\n                sessionContext,\n                applicationContext,\n                new SingletonContext(),\n                new DependentContext());\n\n        // Add custom contexts\n        for (Components c : components) {\n            for (InjectableContext context : c.getContexts()) {\n                if (ApplicationScoped.class.equals(context.getScope())) {\n                    throw new IllegalStateException(\n                            \"Failed to register a context - built-in application context is always active: \" + context);\n                }\n                if (Singleton.class.equals(context.getScope())) {\n                    throw new IllegalStateException(\n                            \"Failed to register a context - built-in singleton context is always active: \" + context);\n                }\n                contextsBuilder.putContext(context);\n            }\n        }\n\n        this.contexts = contextsBuilder.build();\n    }\n\n    static void precomputeBeanRawTypes(Map<String, Set<InjectableBean<?>>> map, InjectableBean<?> bean) {\n        for (Type type : bean.getTypes()) {\n            if (Object.class.equals(type)) {\n                continue;\n            }\n            Class<?> rawType = Types.getRawType(type);\n            if (rawType == null) {\n                continue;\n            }","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L215-L251","documentation":"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.","triggerScenarios":"Registering an InjectableContext whose getScope() equals Singleton.class during container construction (via Components passed to Arc initialization).","commonSituations":"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.","solutions":["Drop the custom Singleton context — the built-in one is always active","Use the built-in singleton context's API (e.g. Arc.container().getContext(Singleton.class)) instead of registering a replacement","Register custom contexts only for non-built-in scope annotations"],"exampleFix":"// before\nbuilder.addContext(new MySingletonContext(Singleton.class));\n// after\nInjectableContext ctx = Arc.container().getContext(Singleton.class); // use built-in","handlingStrategy":"validation","validationCode":"if (Singleton.class.equals(myContext.getScope())) throw new IllegalArgumentException(\"use built-in singleton context\");","typeGuard":"boolean isBuiltInScope = Singleton.class.equals(ctx.getScope()) || ApplicationScoped.class.equals(ctx.getScope());","tryCatchPattern":null,"preventionTips":["Rely on the built-in always-active singleton context","Register custom contexts only for custom scope annotations","Audit migrated CDI bootstrap code for explicit built-in scope registrations"],"tags":["cdi","context","bootstrap"],"backgroundTag":"duplicate-context-registration","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}