quarkusio/quarkus · error · IllegalArgumentException

Arguments must be instances of ${InjectableBean.class} and $

Error message

Arguments must be instances of ${InjectableBean.class} and ${CreationalContextImpl.class}: 
bean: ${bean}
ctx: ${ctx}

What it means

The fast path of BeanManagerImpl.getReference() only supports Arc-internal implementations: the bean must be an InjectableBean and the ctx a CreationalContextImpl. Any other implementations (e.g. from another CDI container, mock Bean/Contextual implementations) cannot be handled and trigger this IllegalArgumentException.

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java:77

        Objects.requireNonNull(bean, "Bean is null");
        Objects.requireNonNull(beanType, "Bean type is null");
        Objects.requireNonNull(ctx, "CreationalContext is null");
        if (!BeanTypeAssignabilityRules.instance().matches(beanType, bean.getTypes())) {
            throw new IllegalArgumentException("Type " + beanType + " is not a bean type of " + bean
                    + "; its bean types are: " + bean.getTypes());
        }
        if (bean instanceof InjectableBean && ctx instanceof CreationalContextImpl) {
            // there's no actual injection point or an `Instance` object,
            // the "current" injection point must be `null`
            InjectionPoint prev = InjectionPointProvider.setCurrent(ctx, null);
            try {
                return ArcContainerImpl.beanInstanceHandle((InjectableBean) bean, (CreationalContextImpl) ctx,
                        null, null, true).get();
            } finally {
                InjectionPointProvider.setCurrent(ctx, prev);
            }
        }
        throw new IllegalArgumentException(
                "Arguments must be instances of " + InjectableBean.class + " and " + CreationalContextImpl.class + ": \nbean: "
                        + bean + "\nctx: " + ctx);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @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,

View on GitHub (pinned to e1c734241f)

Solutions

  1. Obtain the Bean via Arc's own APIs (beanManager.getBeans / Arc.container()) so you get an InjectableBean
  2. Create the CreationalContext with beanManager.createCreationalContext(bean) so it is a CreationalContextImpl
  3. For fakes in tests, subclass/wrap the real Arc types instead of implementing the interfaces from scratch

Example fix

// before
CreationalContext<Object> ctx = myFakeCtxFactory.create();
bm.getReference(bean, type, ctx); // throws

// after
CreationalContext<Object> ctx = bm.createCreationalContext(bean);
bm.getReference(bean, type, ctx);
Defensive patterns

Strategy: validation

Validate before calling

if (!(bean instanceof InjectableBean) || !(ctx instanceof CreationalContextImpl)) {
    throw new IllegalStateException("Use Arc-provided Bean and CreationalContext instances");
}
Object ref = bm.getReference(bean, beanType, ctx);

Type guard

boolean isArcManaged(Bean<?> b, CreationalContext<?> c) {
    return b instanceof InjectableBean && c instanceof CreationalContextImpl;
}

Try / catch

try {
    return bm.getReference(bean, type, ctx);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Arguments must be instances of")) {
        ctx = bm.createCreationalContext(bean);
        return bm.getReference(bean, type, ctx);
    } else throw e;
}

Prevention

When it happens

Trigger: Calling getReference with a Bean<?> that is not Arc's InjectableBean (custom Bean implementation, bean from a different provider) or a CreationalContext created outside Arc (mock or foreign implementation).

Common situations: Testing code with Mockito/fake Bean and CreationalContext implementations; running code written against Weld's API on Quarkus; wrapping/decorating beans in an extension and losing the original Arc instance.

Related errors


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