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

  1. Create the context via beanManager.createCreationalContext(contextual) before calling getInjectableReference
  2. Use Arc.container().beanInstanceHandle(...) or inject the bean directly instead of manual reference creation
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/37dc39ba2d1df95f. Report an issue: GitHub.