{"record":{"id":"981aac96f829221b","repo":"quarkusio/quarkus","slug":"no-active-context-found-for-scopetype","errorCode":null,"errorMessage":"No active context found for: ${scopeType}","messagePattern":"No active context found for: (.+?)","errorType":"exception","errorClass":"ContextNotActiveException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java","lineNumber":228,"sourceCode":"    public boolean areInterceptorBindingsEquivalent(Annotation interceptorBinding1, Annotation interceptorBinding2) {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public int getQualifierHashCode(Annotation qualifier) {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public int getInterceptorBindingHashCode(Annotation interceptorBinding) {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public Context getContext(Class<? extends Annotation> scopeType) {\n        Context context = Arc.requireContainer().getActiveContext(scopeType);\n        if (context == null) {\n            throw new ContextNotActiveException(\"No active context found for: \" + scopeType);\n        }\n        return context;\n    }\n\n    @Override\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    public Collection<Context> getContexts(Class<? extends Annotation> scopeType) {\n        return (Collection) Arc.requireContainer().getContexts(scopeType);\n    }\n\n    @Override\n    public ELResolver getELResolver() {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public ExpressionFactory wrapExpressionFactory(ExpressionFactory expressionFactory) {\n        throw new UnsupportedOperationException();","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java#L210-L246","documentation":"BeanManagerImpl.getContext() delegates to Arc.requireContainer().getActiveContext(scopeType) and throws ContextNotActiveException when no context for the requested scope is currently active. This is the standard CDI signal that you are touching a scoped bean outside its active context (e.g. request-scoped code outside a request).","triggerScenarios":"Calling getContext(RequestScoped.class) (or accessing a @RequestScoped/@SessionScoped bean) from a background thread, @Scheduled task, startup event, Vert.x worker, or any place where the scope's context was never activated.","commonSituations":"ApplicationScope vs request scope confusion in async code; accessing RequestScoped beans from Kafka/AMQP message consumers, gRPC worker threads, or executors; code run before/after the HTTP request ends; tests without quarkus test request setup.","solutions":["Run the code inside the appropriate context (e.g. activate RequestScoped context via Arc.container().requestContext().activate() / terminate)","Change the bean's scope to @ApplicationScoped (or another always-active scope) if per-request state is not needed","Pass required data explicitly instead of reading request-scoped beans from background threads","In Quarkus messaging/scheduler code, use @ActivateRequestContext on the method that touches the scoped bean"],"exampleFix":"// before\n@Scheduled(every = \"10s\")\nvoid run() { requestScopedBean.doWork(); } // context not active\n\n// after\n@Scheduled(every = \"10s\")\n@ActivateRequestContext\nvoid run() { requestScopedBean.doWork(); }","handlingStrategy":"try-catch","validationCode":"if (Arc.container().getActiveContext(RequestScoped.class) == null) {\n    LOGGER.warn(\"Request context not active; activating\");\n    Arc.container().requestContext().activate();\n}","typeGuard":null,"tryCatchPattern":"try {\n    Context ctx = bm.getContext(RequestScoped.class);\n    ...\n} catch (ContextNotActiveException e) {\n    Arc.container().requestContext().activate();\n    try { ... } finally { Arc.container().requestContext().terminate(); }\n}","preventionTips":["Never touch @RequestScoped beans from background threads, schedulers, or message consumers without @ActivateRequestContext","Prefer @ApplicationScoped for stateless beans used across threads","Pass needed values as method parameters instead of relying on request-scoped state in async code","In tests, use QuarkusTest with an active request context (e.g. RestAssured calls) rather than direct bean access"],"tags":["cdi","context-not-active","scopes"],"backgroundTag":"context-not-active","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"}