{"record":{"id":"9e1c1f4ec6d7d85b","repo":"quarkusio/quarkus","slug":"invalid-injection-of-decorator-t-bean-can-only-b","errorCode":null,"errorMessage":"Invalid injection of Decorator<T> bean, can only be used in decorators but was detected in: ${injectionPointInfo.getTargetInfo()}","messagePattern":"Invalid injection of Decorator<T> bean, can only be used in 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":88,"sourceCode":"            // the container automatically detects the problem and treats it as a definition error.\n            if (injectionPointInfo.getType().name().equals(DotNames.INTERCEPTOR_BEAN)) {\n                throw new DefinitionException(\"Invalid injection of Interceptor<T> bean, can only be used in interceptors \" +\n                        \"but was detected in: \" + injectionPointInfo.getTargetInfo());\n            }\n\n            // If a Bean instance with qualifier @Intercepted is injected into a bean instance other than an interceptor\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.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","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L70-L106","documentation":"Per the CDI spec, a Decorator<T> instance may only be injected into a decorator instance. ArC detects a Decorator<T> injection point inside a regular managed bean, synthetic bean, or producer method at build time and throws this DefinitionException.","triggerScenarios":"Declaring @Inject Decorator<MyType> (or Instance<Decorator<...>>) in a normal bean, synthetic bean, or producer method rather than in a @Decorator class.","commonSituations":"Trying to enumerate or invoke decorators from business logic; copying metadata injection code from a decorator class into a service.","solutions":["Move the Decorator<T> injection point into a @Decorator class","Apply the decoration via @Delegate inside a decorator instead of injecting Decorator<T> manually","Remove the injection point if the metadata is unused"],"exampleFix":"// before\n@ApplicationScoped class Svc { @Inject Decorator<Svc> decorator; }\n// after\n@Decorator abstract class SvcDecorator { @Inject Decorator<Object> decorator; @Delegate @Any Object delegate; }","handlingStrategy":"validation","validationCode":"boolean ok = java.util.Arrays.stream(MyBean.class.getDeclaredFields())\n    .noneMatch(f -> f.getType().getName().equals(\"jakarta.enterprise.inject.spi.Decorator\"));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inject Decorator<T> only inside @Decorator classes","Use @Delegate delegation for decoration instead of manual decorator lookup","Audit business beans for jakarta.enterprise.inject.spi imports"],"tags":["cdi","arc","decorator","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"}