quarkusio/quarkus · critical · IllegalStateException
No CDI container is available
Error message
No CDI container is available
What it means
ArcCDIProvider.getCDI() throws IllegalStateException when Arc.container() returns null, meaning no CDI container has been initialized (or it was already shut down). CDI.current()/CDIUtils require a running Arc container to return a CDI handle.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcCDIProvider.java:29
import io.quarkus.arc.Arc;
/**
*
* @author Martin Kouba
*/
public class ArcCDIProvider implements CDIProvider {
private final ArcCDI arcCDI;
public ArcCDIProvider() {
this.arcCDI = new ArcCDI();
}
@Override
public CDI<Object> getCDI() {
if (Arc.container() == null) {
throw new IllegalStateException("No CDI container is available");
}
return arcCDI;
}
static class ArcCDI extends CDI<Object> {
private final Instance<Object> instanceDelegate;
public ArcCDI() {
this.instanceDelegate = Arc.requireContainer().beanManager().createInstance();
}
@Override
public Instance<Object> select(Annotation... qualifiers) {
return instanceDelegate.select(qualifiers);
}
@OverrideView on GitHub (pinned to e1c734241f)
Solutions
- Ensure the application/container is started before calling CDI.current() (in Quarkus, run within a @QuarkusTest or the running app)
- In plain tests, call Arc.initialize() first and Arc.shutdown() in @AfterAll
- Avoid static-initializer use of CDI.current(); obtain beans lazily at runtime
- Check for accidental Arc.shutdown() calls or container restarts preceding the access
Example fix
// before
MyBean b = CDI.current().select(MyBean.class).get(); // IllegalStateException in plain test
// after
Arc.initialize();
try {
MyBean b = CDI.current().select(MyBean.class).get();
} finally {
Arc.shutdown();
} Defensive patterns
Strategy: validation
Validate before calling
ArcContainer c = Arc.container(); if (c == null) { Arc.initialize(); } Type guard
boolean ready = Arc.container() != null;
Try / catch
try { CDI<Object> cdi = CDI.current(); } catch (IllegalStateException e) { Arc.initialize(); CDI<Object> cdi = CDI.current(); } Prevention
- Never call CDI.current() in static initializers
- In tests, initialize Arc in @BeforeAll and shut down in @AfterAll
- Guard against premature Arc.shutdown() in lifecycle code
When it happens
Trigger: Calling CDI.current() or the CDIProvider.getCDI() before Arc.initialize(), after Arc.shutdown(), or in a process/ClassLoader where the Arc container was never started (plain unit tests, static initializers, early startup code).
Common situations: Unit tests exercising CDI code without QuarkusTest; code running in a static field initializer before the container boots; use of CDI.current() in a separate thread before/after application lifecycle; calling CDI.current() during container shutdown.
Related errors
- The Reactive REST Client needs to be built within the contex
- Links context has not been initialized
- Getter accessors container has not been initialized
- Multiple @PostConstruct interceptor methods declared on clas
- Multiple @PreDestroy interceptor methods declared on class:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/ebc70ecc5b445821.
Report an issue: GitHub.