{"record":{"id":"ad8c297dd5bcf6e2","repo":"quarkusio/quarkus","slug":"failed-to-register-a-context-built-in-applicatio","errorCode":null,"errorMessage":"Failed to register a context - built-in application context is always active: \" + context","messagePattern":"Failed to register a context - built-in application 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":229,"sourceCode":"                notifierOrNull(Set.of(Destroyed.Literal.REQUEST, Any.Literal.INSTANCE)),\n                requestContextInstances != null ? requestContextInstances : ComputingCacheContextInstances::new);\n        SessionContext sessionContext = new SessionContext(this.currentContextFactory.create(SessionScoped.class),\n                notifierOrNull(Set.of(Initialized.Literal.SESSION, Any.Literal.INSTANCE)),\n                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            }","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L211-L247","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the custom ApplicationScoped context registration — rely on the always-active built-in one","If a custom lifecycle is needed, register the context under a different scope annotation","Upgrade custom context code to extend/wrap existing behavior instead of replacing the built-in context"],"exampleFix":"// before\nbuilder.addContext(new MyApplicationContext(ApplicationScoped.class));\n// after\n@Singleton // or a custom scope annotation\nclass MyContext { } // use built-in application context instead","handlingStrategy":"validation","validationCode":"if (ApplicationScoped.class.equals(myContext.getScope())) throw new IllegalArgumentException(\"use built-in application context\");","typeGuard":"boolean isBuiltInScope = ApplicationScoped.class.equals(ctx.getScope()) || Singleton.class.equals(ctx.getScope());","tryCatchPattern":null,"preventionTips":["Never register contexts for built-in scopes (ApplicationScoped, Singleton)","Register custom contexts only for custom scope annotations","Review embedded/test CDI setups for context overrides"],"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-14T00:17:10.932Z"}