{"record":{"id":"42bf1c18bb09e0d4","repo":"quarkusio/quarkus","slug":"invalid-injection-of-decorated-bean-t-can-only","errorCode":null,"errorMessage":"Invalid injection of @Decorated Bean<T>, can only be injected into decorators but was detected in: ${injectionPointInfo.getTargetInfo()}","messagePattern":"Invalid injection of @Decorated Bean<T>, can only be injected into decorators but was detected in: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java","lineNumber":96,"sourceCode":"            if (injectionPointInfo.getType().name().equals(DotNames.BEAN)\n                    && injectionPointInfo.getRequiredQualifier(DotNames.INTERCEPTED) != null) {\n                throw new DefinitionException(\n                        \"Invalid injection of @Intercepted Bean<T>, can only be injected into interceptors \" +\n                                \"but was detected in: \" + injectionPointInfo.getTargetInfo());\n            }\n\n            // If a Decorator<T> instance is injected into a bean instance other than a decorator instance,\n            // the container automatically detects the problem and treats it as a definition error.\n            if (injectionPointInfo.getType().name().equals(DotNames.DECORATOR)) {\n                throw new DefinitionException(\"Invalid injection of Decorator<T> bean, can only be used in decorators \" +\n                        \"but was detected in: \" + injectionPointInfo.getTargetInfo());\n            }\n\n            // If a Bean instance with qualifier @Decorated is injected into a bean instance other than a decorator\n            // instance, the container automatically detects the problem and treats it as a definition error.\n            if (injectionPointInfo.getType().name().equals(DotNames.BEAN)\n                    && injectionPointInfo.getRequiredQualifier(DotNames.DECORATED) != null) {\n                throw new DefinitionException(\n                        \"Invalid injection of @Decorated Bean<T>, can only be injected into decorators \" +\n                                \"but was detected in: \" + injectionPointInfo.getTargetInfo());\n            }\n\n            // the injection point is a field, an initializer method parameter or a bean constructor, with qualifier\n            // @Default, then the type parameter of the injected Bean, or Interceptor must be the same as the type\n            // declaring the injection point\n            if (injectionPointInfo.getRequiredType().name().equals(DotNames.BEAN)\n                    && injectionPointInfo.getRequiredType().kind() == Type.Kind.PARAMETERIZED_TYPE\n                    && injectionPointInfo.getRequiredType().asParameterizedType().arguments().size() == 1\n                    && injectionPointInfo.hasDefaultedQualifier()) {\n                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) {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L78-L114","documentation":"Per CDI 4.1, a Bean instance qualified @Decorated may only be injected into a decorator instance. ArC detects such an injection into a regular managed bean, synthetic bean, or producer method at build time and throws this DefinitionException.","triggerScenarios":"Injecting @Inject @Decorated Bean<MyBean> into a non-decorator bean, synthetic bean, or producer method.","commonSituations":"Attempting to access decorated-bean metadata outside decorators; adapting interceptor-only examples to decorators; generic metadata helpers.","solutions":["Move the @Decorated Bean<T> injection into a @Decorator class","Remove the @Decorated qualifier if plain Bean<T> metadata suffices","Use Instance<T>/programmatic lookup if the actual instance is what you need"],"exampleFix":"// before\n@ApplicationScoped class Svc { @Inject @Decorated Bean<Svc> self; }\n// after\n@Decorator class SvcDecorator { @Inject @Decorated Bean<Object> decoratedBean; }","handlingStrategy":"validation","validationCode":"boolean ok = java.util.Arrays.stream(MyBean.class.getDeclaredFields())\n    .noneMatch(f -> f.isAnnotationPresent(jakarta.enterprise.inject.Decorated.class));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["@Decorated Bean<?> belongs only in decorator classes","Drop the qualifier if plain Bean<T> metadata suffices","Do not copy interceptor metadata snippets into decorators or beans without adjusting qualifiers"],"tags":["cdi","arc","decorated","bean-metadata","build-time"],"backgroundTag":"cdi-bean-metadata-injection","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"}