quarkusio/quarkus · error · IllegalStateException
Cannot create bean
Error message
Cannot create bean
What it means
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.
Source
Thrown at extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/HttpSessionContext.java:151
.collect(Collectors.toList()));
}
instances.clear();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private ComputingCache<Key, ContextInstanceHandle<?>> getContextualInstances(HttpSession session) {
ComputingCache<Key, ContextInstanceHandle<?>> contextualInstances = (ComputingCache<Key, ContextInstanceHandle<?>>) session
.getAttribute(CONTEXTUAL_INSTANCES_KEY);
if (contextualInstances == null) {
synchronized (this) {
contextualInstances = (ComputingCache<Key, ContextInstanceHandle<?>>) session
.getAttribute(CONTEXTUAL_INSTANCES_KEY);
if (contextualInstances == null) {
contextualInstances = new ComputingCache<>(key -> {
InjectableBean bean = Arc.container().bean(key.beanIdentifier);
if (key.creationalContext == null) {
throw new IllegalStateException("Cannot create bean ");
}
return new ContextInstanceHandleImpl(bean, bean.create(key.creationalContext), key.creationalContext);
});
session.setAttribute(CONTEXTUAL_INSTANCES_KEY, contextualInstances);
}
}
}
return contextualInstances;
}
private HttpSession session(boolean create) {
HttpSession session = null;
try {
session = ((HttpServletRequest) ServletRequestContext.requireCurrent().getServletRequest()).getSession(create);
} catch (IllegalStateException ignored) {
session = DESTRUCT_SESSION.get();
}
return session;View on GitHub (pinned to e1c734241f)
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
Example fix
// before: relying on serialized CDI session beans across redeploy
// quarkus.undertow... persistent sessions enabled
// after: disable persistence or clear stale sessions on startup
public class SessionCleaner {
@Inject ServletContext ctx;
// clear old sessions / use in-memory sessions only
} Defensive patterns
Strategy: validation
Validate before calling
// ensure session state is not stale
if (request.getRequestedSessionId() != null && appVersionChanged) {
request.changeSessionId(); // or invalidate()
} Try / catch
try {
bean = container.instance(MySessionBean.class).get();
} catch (IllegalStateException e) {
session.invalidate(); // drop corrupted session state
} Prevention
- Invalidate sessions on redeploy
- Keep cluster nodes on identical Quarkus versions
- Store only Serializable, app-level data in sessions
When it happens
Trigger: 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.
Common situations: Hot redeploy with persistent sessions; sticky-session failover across nodes running different Quarkus versions; cluster replication of CDI session beans.
Related errors
- Failed to record call to method ${call.method}
- Failed to substitute ${param}
- Cannot serialise field '${i.getName()}' on object '${param}'
- Couldn't load object of type ${i.propertyType.getName()} for
- Multiple @Inject constructors on ${theClass}
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/3068a4f586735cc2.
Report an issue: GitHub.