{"record":{"id":"3068a4f586735cc2","repo":"quarkusio/quarkus","slug":"cannot-create-bean","errorCode":null,"errorMessage":"Cannot create bean ","messagePattern":"Cannot create bean ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/HttpSessionContext.java","lineNumber":151,"sourceCode":"                                .collect(Collectors.toList()));\n            }\n            instances.clear();\n        }\n    }\n\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    private ComputingCache<Key, ContextInstanceHandle<?>> getContextualInstances(HttpSession session) {\n        ComputingCache<Key, ContextInstanceHandle<?>> contextualInstances = (ComputingCache<Key, ContextInstanceHandle<?>>) session\n                .getAttribute(CONTEXTUAL_INSTANCES_KEY);\n        if (contextualInstances == null) {\n            synchronized (this) {\n                contextualInstances = (ComputingCache<Key, ContextInstanceHandle<?>>) session\n                        .getAttribute(CONTEXTUAL_INSTANCES_KEY);\n                if (contextualInstances == null) {\n                    contextualInstances = new ComputingCache<>(key -> {\n                        InjectableBean bean = Arc.container().bean(key.beanIdentifier);\n                        if (key.creationalContext == null) {\n                            throw new IllegalStateException(\"Cannot create bean \");\n                        }\n                        return new ContextInstanceHandleImpl(bean, bean.create(key.creationalContext), key.creationalContext);\n                    });\n                    session.setAttribute(CONTEXTUAL_INSTANCES_KEY, contextualInstances);\n                }\n            }\n        }\n        return contextualInstances;\n    }\n\n    private HttpSession session(boolean create) {\n        HttpSession session = null;\n        try {\n            session = ((HttpServletRequest) ServletRequestContext.requireCurrent().getServletRequest()).getSession(create);\n        } catch (IllegalStateException ignored) {\n            session = DESTRUCT_SESSION.get();\n        }\n        return session;","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/HttpSessionContext.java#L133-L169","documentation":"HttpSessionContext (ArC-backed CDI session context for Undertow) stores session-scoped bean instances in the HTTP session. This error means a bean identifier key was found in the session cache but there is no creational context recorded, so the bean cannot be instantiated. It indicates corrupted/incomplete session state, typically after deserialization of a session created by a different app version.","triggerScenarios":"A serialized HttpSession is restored (e.g. after redeploy or session replication) with CONTEXTUAL_INSTANCES_KEY entries that lack creational contexts; a ContextInstanceHandle is manipulated so creationalContext is null; internal state mismatch between ArC versions.","commonSituations":"Hot redeploy with persistent sessions; sticky-session failover across nodes running different Quarkus versions; cluster replication of CDI session beans.","solutions":["Clear HTTP sessions (restart server with fresh session storage or clear session persistence dir)","Disable session persistence/replication for CDI-scoped beans or mark dependent data Serializable and manage it in the app layer instead","Ensure all nodes in a cluster run the same Quarkus/ArC version","Reproduce with a fresh session to confirm the problem is stale serialized state"],"exampleFix":"// before: relying on serialized CDI session beans across redeploy\n// quarkus.undertow... persistent sessions enabled\n// after: disable persistence or clear stale sessions on startup\npublic class SessionCleaner {\n    @Inject ServletContext ctx;\n    // clear old sessions / use in-memory sessions only\n}","handlingStrategy":"validation","validationCode":"// ensure session state is not stale\nif (request.getRequestedSessionId() != null && appVersionChanged) {\n    request.changeSessionId(); // or invalidate()\n}","typeGuard":null,"tryCatchPattern":"try {\n    bean = container.instance(MySessionBean.class).get();\n} catch (IllegalStateException e) {\n    session.invalidate(); // drop corrupted session state\n}","preventionTips":["Invalidate sessions on redeploy","Keep cluster nodes on identical Quarkus versions","Store only Serializable, app-level data in sessions"],"tags":["cdi","session","undertow","serialization","quarkus"],"backgroundTag":"invalid-session-state","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"}