{"record":{"id":"33200d7dc2ac78e0","repo":"quarkusio/quarkus","slug":"type-of-injected-bean-t-does-not-match-the-type-o","errorCode":null,"errorMessage":"Type of injected Bean<T> does not match the type of the bean declaring the injection point. Problematic injection point: ${injectionPointInfo.getTargetInfo()}","messagePattern":"Type of injected Bean<T> does not match the type of the bean declaring the injection point\\. Problematic injection point: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java","lineNumber":126,"sourceCode":"                Type actualType = injectionPointInfo.getRequiredType().asParameterizedType().arguments().get(0);\n                AnnotationTarget ipTarget = injectionPointInfo.getAnnotationTarget();\n                DotName expectedType = null;\n                if (ipTarget.kind() == Kind.FIELD) {\n                    // field injection derives this from the class\n                    expectedType = ipTarget.asField().declaringClass().name();\n                } else if (ipTarget.kind() == Kind.METHOD_PARAMETER) {\n                    // the injection point is a producer method parameter then the type parameter of the injected Bean\n                    // must be the same as the producer method return type\n                    if (beanType == BeanType.PRODUCER_METHOD) {\n                        expectedType = ipTarget.asMethodParameter().method().returnType().name();\n                    } else {\n                        expectedType = ipTarget.asMethodParameter().method().declaringClass().name();\n                    }\n                }\n                if (expectedType != null\n                        // This is very rudimentary check, might need to be expanded?\n                        && !expectedType.equals(actualType.name())) {\n                    throw new DefinitionException(\n                            \"Type of injected Bean<T> does not match the type of the bean declaring the \" +\n                                    \"injection point. Problematic injection point: \" + injectionPointInfo.getTargetInfo());\n                }\n            }\n        }\n        if (beanType == BeanType.INTERCEPTOR) {\n            // the injection point is a field, an initializer method parameter or a bean constructor of an interceptor,\n            // with qualifier @Intercepted, then the type parameter of the injected Bean must be an unbounded wildcard\n            if (injectionPointInfo.getRequiredType().name().equals(DotNames.BEAN)\n                    && injectionPointInfo.getRequiredQualifier(DotNames.INTERCEPTED) != null\n                    && injectionPointInfo.getRequiredType().kind() == Type.Kind.PARAMETERIZED_TYPE) {\n                ParameterizedType parameterizedType = injectionPointInfo.getRequiredType().asParameterizedType();\n                // there should be exactly one param - wildcard - and it has to be unbound; all else is DefinitionException\n                if (parameterizedType.arguments().size() != 1\n                        || !(parameterizedType.arguments().get(0).kind() == Type.Kind.WILDCARD_TYPE)\n                        || !(parameterizedType.arguments().get(0).asWildcardType().extendsBound().name().equals(DotNames.OBJECT)\n                                && parameterizedType.arguments().get(0).asWildcardType().superBound() == null)) {\n                    throw new DefinitionException(","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L108-L144","documentation":"When Bean<T> is injected into a bean with qualifier @Default, the CDI spec requires T to match the declaring bean's own type. ArC performs a (deliberately rudimentary) check comparing the injection point's declaring class against the Bean<T> type parameter and throws this DefinitionException when they differ.","triggerScenarios":"Injecting Bean<SomeOtherType> (with @Default qualifier) into a bean of a different type, e.g. class Foo { @Inject Bean<Bar> barMeta; }.","commonSituations":"Copying metadata injection snippets between classes without changing the type parameter; using Object or a base class instead of the exact declaring bean type.","solutions":["Change the type parameter to the exact type of the bean declaring the injection point","Use an unbound wildcard Bean<?> if you don't need the typed parameter (note: specific wildcard rules apply)","Remove the @Default qualifier / injection if it was unintentional"],"exampleFix":"// before\nclass MyService { @Inject Bean<OtherService> otherMeta; }\n// after\nclass MyService { @Inject Bean<MyService> selfMeta; }","handlingStrategy":"validation","validationCode":"Field f = MyBean.class.getDeclaredField(\"meta\");\nif (Bean.class == f.getType() && f.getAnnotations().length == 0)\n    throw new IllegalStateException(\"Bean<T> with @Default must use T = \" + MyBean.class.getName());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the type parameter to the declaring bean class exactly","Use Bean<?> only where the spec allows wildcards","Double-check metadata injection snippets copied between classes"],"tags":["cdi","arc","bean-metadata","generics","build-time"],"backgroundTag":"cdi-bean-metadata-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"}