{"record":{"id":"a19e5a00cde67b2d","repo":"quarkusio/quarkus","slug":"arguments-must-be-instances-of-injectablebean-cl","errorCode":null,"errorMessage":"Arguments must be instances of ${InjectableBean.class} and ${CreationalContextImpl.class}: \nbean: ${bean}\nctx: ${ctx}","messagePattern":"Arguments must be instances of (.+?) and (.+?): \nbean: (.+?)\nctx: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java","lineNumber":77,"sourceCode":"        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\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    @Override\n    public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx) {\n        Objects.requireNonNull(ij, \"InjectionPoint is null\");\n        Objects.requireNonNull(ctx, \"CreationalContext is null\");\n        if (ctx instanceof CreationalContextImpl) {\n            Set<Bean<?>> beans = getBeans(ij.getType(), ij.getQualifiers().toArray(new Annotation[] {}));\n            if (beans.isEmpty()) {\n                throw new UnsatisfiedResolutionException();\n            }\n            InjectableBean<?> bean = (InjectableBean<?>) resolve(beans);\n            InjectionPoint prev = InjectionPointProvider.setCurrent(ctx, ij);\n            try {\n                return ArcContainerImpl.beanInstanceHandle(bean, (CreationalContextImpl) ctx,","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java#L59-L95","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Obtain the Bean via Arc's own APIs (beanManager.getBeans / Arc.container()) so you get an InjectableBean","Create the CreationalContext with beanManager.createCreationalContext(bean) so it is a CreationalContextImpl","For fakes in tests, subclass/wrap the real Arc types instead of implementing the interfaces from scratch"],"exampleFix":"// before\nCreationalContext<Object> ctx = myFakeCtxFactory.create();\nbm.getReference(bean, type, ctx); // throws\n\n// after\nCreationalContext<Object> ctx = bm.createCreationalContext(bean);\nbm.getReference(bean, type, ctx);","handlingStrategy":"validation","validationCode":"if (!(bean instanceof InjectableBean) || !(ctx instanceof CreationalContextImpl)) {\n    throw new IllegalStateException(\"Use Arc-provided Bean and CreationalContext instances\");\n}\nObject ref = bm.getReference(bean, beanType, ctx);","typeGuard":"boolean isArcManaged(Bean<?> b, CreationalContext<?> c) {\n    return b instanceof InjectableBean && c instanceof CreationalContextImpl;\n}","tryCatchPattern":"try {\n    return bm.getReference(bean, type, ctx);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Arguments must be instances of\")) {\n        ctx = bm.createCreationalContext(bean);\n        return bm.getReference(bean, type, ctx);\n    } else throw e;\n}","preventionTips":["Always create contexts with beanManager.createCreationalContext()","Never mock Bean/CreationalContext with interface stubs in tests — wrap real Arc objects","Don't mix beans/contexts from other CDI implementations (Weld) into Arc APIs"],"tags":["cdi","illegal-argument","beanmanager"],"backgroundTag":"incompatible-cdi-implementation","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"}