{"record":{"id":"44d28730fdd71982","repo":"quarkusio/quarkus","slug":"type-beantype-is-not-a-bean-type-of-bean-it","errorCode":null,"errorMessage":"Type ${beanType} is not a bean type of ${bean}; its bean types are: ${bean.getTypes()}","messagePattern":"Type (.+?) is not a bean type of (.+?); its bean types are: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java","lineNumber":63,"sourceCode":"\nimport io.quarkus.arc.Arc;\nimport io.quarkus.arc.InjectableBean;\n\n/**\n * @author Martin Kouba\n */\npublic class BeanManagerImpl implements BeanManager {\n\n    static final LazyValue<BeanManagerImpl> INSTANCE = new LazyValue<>(BeanManagerImpl::new);\n\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    @Override\n    public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> ctx) {\n        Objects.requireNonNull(bean, \"Bean is null\");\n        Objects.requireNonNull(beanType, \"Bean type is null\");\n        Objects.requireNonNull(ctx, \"CreationalContext is null\");\n        if (!BeanTypeAssignabilityRules.instance().matches(beanType, bean.getTypes())) {\n            throw new IllegalArgumentException(\"Type \" + beanType + \" is not a bean type of \" + bean\n                    + \"; its bean types are: \" + bean.getTypes());\n        }\n        if (bean instanceof InjectableBean && ctx instanceof CreationalContextImpl) {\n            // there's no actual injection point or an `Instance` object,\n            // the \"current\" injection point must be `null`\n            InjectionPoint prev = InjectionPointProvider.setCurrent(ctx, null);\n            try {\n                return ArcContainerImpl.beanInstanceHandle((InjectableBean) bean, (CreationalContextImpl) ctx,\n                        null, null, true).get();\n            } finally {\n                InjectionPointProvider.setCurrent(ctx, prev);\n            }\n        }\n        throw new IllegalArgumentException(\n                \"Arguments must be instances of \" + InjectableBean.class + \" and \" + CreationalContextImpl.class + \": \\nbean: \"\n                        + bean + \"\\nctx: \" + ctx);\n    }\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java#L45-L81","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nObject ref = bm.getReference(bean, UnrelatedType.class, ctx); // throws\n\n// after\nif (BeanTypeAssignabilityRules.instance().matches(UnrelatedType.class, bean.getTypes())) {\n    Object ref = bm.getReference(bean, UnrelatedType.class, ctx);\n}","handlingStrategy":"validation","validationCode":"if (!BeanTypeAssignabilityRules.instance().matches(beanType, bean.getTypes())) {\n    throw new IllegalArgumentException(beanType + \" is not a bean type of \" + bean);\n}\nObject ref = bm.getReference(bean, beanType, ctx);","typeGuard":"boolean isBeanTypeOf(Bean<?> bean, Type type) {\n    return BeanTypeAssignabilityRules.instance().matches(type, bean.getTypes());\n}","tryCatchPattern":"try {\n    return bm.getReference(bean, type, ctx);\n} catch (IllegalArgumentException e) {\n    LOGGER.errorf(\"Type %s not among %s\", type, bean.getTypes());\n    throw e;\n}","preventionTips":["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"],"tags":["cdi","bean-types","illegal-argument"],"backgroundTag":"bean-type-mismatch","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}