quarkusio/quarkus · error · jakarta.enterprise.inject.CreationException
CreationException wrapping original cause from constructor i
Error message
CreationException wrapping original cause from constructor invocation failure
What it means
Reflections.newInstance() invokes a bean constructor reflectively. If the constructor itself throws, the original cause is unwrapped and rethrown: as RuntimeException, Error, or — since this is only used to instantiate beans — wrapped in a jakarta.enterprise.inject.CreationException. The message in the error record corresponds to that CreationException wrapping path.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Reflections.java:143
public static Object newInstance(Class<?> clazz, Class<?>[] parameterTypes, Object[] args) {
Constructor<?> constructor = findConstructor(clazz, parameterTypes);
if (constructor != null) {
if (!constructor.canAccess(null)) {
constructor.setAccessible(true);
}
try {
return constructor.newInstance(args);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
// this method is only used to instantiate beans, so throwing `CreationException` is fine
throw new CreationException(cause);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException("Cannot invoke constructor: " + clazz.getName(), e);
}
}
throw new RuntimeException(
"No " + clazz.getName() + "constructor found for params: " + Arrays.toString(parameterTypes));
}
public static Object readField(Class<?> clazz, String name, Object instance) {
try {
Field field = clazz.getDeclaredField(name);
if (!field.canAccess(instance)) {
field.setAccessible(true);
}
return field.get(instance);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Cannot read field value: " + clazz.getName() + "#" + name, e);
}View on GitHub (pinned to e1c734241f)
Solutions
- Read getCause() of the CreationException — the root stack trace names the failing line in your constructor.
- Keep constructors minimal: inject dependencies and defer work to @PostConstruct or first use.
- Use constructor parameter injection instead of field injection so required values are available at construction.
- Validate external prerequisites (config properties, connections) before/inside bean creation with clear failure messages.
Example fix
// before
@ApplicationScoped
class Repo { @Inject Config cfg; Repo() { connect(cfg.url()); } } // cfg null in constructor
// after
@ApplicationScoped
class Repo { private final Config cfg; Repo(Config cfg) { this.cfg = cfg; }
@PostConstruct void init() { connect(cfg.url()); } } Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight: resolve the bean early so constructor failures surface at startup Arc.container().instance(MyBean.class).get();
Try / catch
try {
MyBean bean = Arc.container().instance(MyBean.class).get();
} catch (CreationException e) {
Throwable root = e.getCause();
log.error("Bean construction failed — root cause:", root);
throw new IllegalStateException("Fix constructor logic/config: " + root.getMessage(), root);
} Prevention
- Keep constructors free of side effects and external calls
- Use constructor injection, not field injection, for required collaborators
- Defer initialization work to @PostConstruct or lazy first use
- Fail fast with clear messages when config/env prerequisites are missing
When it happens
Trigger: A bean constructor throws during container initialization (Arc.container().instance(...), @PostConstruct-time injection, programmatic lookup) — e.g. it throws NPE/IllegalStateException, and the container surfaces it as CreationException with the original cause.
Common situations: Constructor performs heavy logic that fails (missing config property, DB not up, null injection into constructor using field injection); missing dependency at runtime; environment misconfiguration (missing env var, wrong URL) surfacing at bean creation.
Related errors
- Not a valid type:
- Error checking value of member method ${methodName} on ${dec
- Quarkus does not support CDI Full @Specializes annotation; t
- IllegalStateException wrapping ClassNotFoundException for ge
- Unable to derive the logger name at ${injectionPoint}
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/83d026ab19e01b81.
Report an issue: GitHub.