quarkusio/quarkus · error · IllegalArgumentException
CreationalContext must be an instances of ${CreationalContex
Error message
CreationalContext must be an instances of ${CreationalContextImpl.class} What it means
getInjectableReference() requires the CreationalContext argument to be Arc's internal CreationalContextImpl; any other implementation cannot participate in Arc's lifecycle (dependent destruction, interception) and causes this IllegalArgumentException. Note the message contains a typo ('must be an instances of') from the source.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java:101
@Override
public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx) {
Objects.requireNonNull(ij, "InjectionPoint is null");
Objects.requireNonNull(ctx, "CreationalContext is null");
if (ctx instanceof CreationalContextImpl) {
Set<Bean<?>> beans = getBeans(ij.getType(), ij.getQualifiers().toArray(new Annotation[] {}));
if (beans.isEmpty()) {
throw new UnsatisfiedResolutionException();
}
InjectableBean<?> bean = (InjectableBean<?>) resolve(beans);
InjectionPoint prev = InjectionPointProvider.setCurrent(ctx, ij);
try {
return ArcContainerImpl.beanInstanceHandle(bean, (CreationalContextImpl) ctx,
null, null, true).get();
} finally {
InjectionPointProvider.setCurrent(ctx, prev);
}
}
throw new IllegalArgumentException(
"CreationalContext must be an instances of " + CreationalContextImpl.class);
}
@Override
public <T> CreationalContext<T> createCreationalContext(Contextual<T> contextual) {
return new CreationalContextImpl<>(contextual);
}
@Override
public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers) {
return ArcContainerImpl.instance().getBeans(Objects.requireNonNull(beanType), qualifiers);
}
@Override
public Set<Bean<?>> getBeans(String name) {
return ArcContainerImpl.instance().getBeans(Objects.requireNonNull(name));
}
View on GitHub (pinned to e1c734241f)
Solutions
- Create the context via beanManager.createCreationalContext(contextual) before calling getInjectableReference
- Use Arc.container().beanInstanceHandle(...) or inject the bean directly instead of manual reference creation
- In tests, wrap the real CreationalContextImpl rather than stubbing the interface
Example fix
// before bm.getInjectableReference(bean, mock(CreationalContext.class)); // after CreationalContext<?> ctx = bm.createCreationalContext(bean); bm.getInjectableReference(bean, ctx);
Defensive patterns
Strategy: validation
Validate before calling
if (!(ctx instanceof CreationalContextImpl)) {
ctx = bm.createCreationalContext(bean);
}
Object ref = bm.getInjectableReference(bean, ctx); Type guard
boolean isArcContext(CreationalContext<?> c) {
return c instanceof CreationalContextImpl;
} Try / catch
try {
return bm.getInjectableReference(bean, ctx);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("CreationalContext must be")) {
return bm.getInjectableReference(bean, bm.createCreationalContext(bean));
} else throw e;
} Prevention
- Create CreationalContext exclusively via beanManager.createCreationalContext()
- Avoid wrapping/proxying CreationalContext in custom lifecycle code
- When porting from Weld, replace all Weld context classes with Arc equivalents
When it happens
Trigger: Calling beanManager.getInjectableReference(bean, ctx) where ctx was created by another container, mocked, or hand-implemented rather than returned from beanManager.createCreationalContext().
Common situations: Porting Weld code to Quarkus; unit tests stubbing CreationalContext; custom lifecycle management code that wraps or proxies the context.
Related errors
- Contextual parameter must not be null
- Not an annotation:
- No interceptor bindings
- The set of bean types must not be empty
- Type ${beanType} is not a bean type of ${bean}; its bean typ
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/37dc39ba2d1df95f.
Report an issue: GitHub.