quarkusio/quarkus · error · IllegalArgumentException
Type ${beanType} is not a bean type of ${bean}; its bean typ
Error message
Type ${beanType} is not a bean type of ${bean}; its bean types are: ${bean.getTypes()} What it means
BeanManagerImpl.getReference() verifies that the requested beanType is actually in the bean's set of legal bean types using BeanTypeAssignabilityRules. Requesting a ClientProxy/contextual reference for a type the bean does not expose is a spec violation, so Arc throws IllegalArgumentException listing the bean's legal types.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java:63
import io.quarkus.arc.Arc;
import io.quarkus.arc.InjectableBean;
/**
* @author Martin Kouba
*/
public class BeanManagerImpl implements BeanManager {
static final LazyValue<BeanManagerImpl> INSTANCE = new LazyValue<>(BeanManagerImpl::new);
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> ctx) {
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);
}
View on GitHub (pinned to e1c734241f)
Solutions
- Request a type contained in bean.getTypes() (check assignability first with BeanTypeAssignabilityRules or types.contains)
- Get the bean via beanManager.getBeans(requestedType, qualifiers) so the bean and type are consistent
- If you need the extra type, expose it on the bean (add the interface to the bean class/producer return type)
Example fix
// before
Object ref = bm.getReference(bean, UnrelatedType.class, ctx); // throws
// after
if (BeanTypeAssignabilityRules.instance().matches(UnrelatedType.class, bean.getTypes())) {
Object ref = bm.getReference(bean, UnrelatedType.class, ctx);
} Defensive patterns
Strategy: validation
Validate before calling
if (!BeanTypeAssignabilityRules.instance().matches(beanType, bean.getTypes())) {
throw new IllegalArgumentException(beanType + " is not a bean type of " + bean);
}
Object ref = bm.getReference(bean, beanType, ctx); Type guard
boolean isBeanTypeOf(Bean<?> bean, Type type) {
return BeanTypeAssignabilityRules.instance().matches(type, bean.getTypes());
} Try / catch
try {
return bm.getReference(bean, type, ctx);
} catch (IllegalArgumentException e) {
LOGGER.errorf("Type %s not among %s", type, bean.getTypes());
throw e;
} Prevention
- Always obtain the Bean via getBeans(requiredType, ...) so bean and type match
- Never hardcode types in getReference calls in framework code
- Re-check lookups after narrowing a bean's exposed types in a refactor
When it happens
Trigger: Calling beanManager.getReference(bean, unrelatedType, creationalContext) where unrelatedType is not assignable to any of bean.getTypes(); mixing a bean handle from one lookup with a type from another; reflection code guessing the wrong type.
Common situations: Framework/tooling code that holds a Bean<?> and requests a reference with a hardcoded or user-supplied type; refactors that narrow a bean's exposed types (e.g. removing an interface) while other code still requests the old type.
Related errors
- Contextual parameter must not be null
- Not an annotation:
- No interceptor bindings
- The set of bean types must not be empty
- Arguments must be instances of ${InjectableBean.class} and $
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/44d28730fdd71982.
Report an issue: GitHub.