{"record":{"id":"24e699ace88ad18f","repo":"quarkusio/quarkus","slug":"invalid-injection-of-intercepted-bean-t-can-onl","errorCode":null,"errorMessage":"Invalid injection of @Intercepted Bean<T>, can only be injected into interceptors but was detected in: ${injectionPointInfo.getTargetInfo()}","messagePattern":"Invalid injection of @Intercepted Bean<T>, can only be injected into interceptors 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":80,"sourceCode":"        return new Injection(null, ret);\n    }\n\n    private static void validateInjections(InjectionPointInfo injectionPointInfo, BeanType beanType) {\n        // Mostly validation related to Bean metadata injection restrictions\n        // see https://jakarta.ee/specifications/cdi/4.1/jakarta-cdi-spec-4.1.html#bean_metadata\n        if (beanType == BeanType.MANAGED_BEAN || beanType == BeanType.SYNTHETIC_BEAN || beanType == BeanType.PRODUCER_METHOD) {\n            // If an Interceptor<T> instance is injected into a bean instance other than an interceptor instance,\n            // 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());","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L62-L98","documentation":"Per CDI 4.1, a Bean instance qualified @Intercepted may only be injected into an interceptor instance. ArC's build-time validation detects such an injection into a regular managed bean, synthetic bean, or producer method and throws this DefinitionException.","triggerScenarios":"Injecting a field like @Inject @Intercepted Bean<MyBean> bean into a normal (non-interceptor) bean, synthetic bean, or producer method.","commonSituations":"Attempting to access the intercepted instance metadata from application code; mimicking examples written for interceptor classes; writing generic cross-cutting helpers that read bean metadata.","solutions":["Move the @Intercepted Bean<T> injection into an interceptor class","Drop the @Intercepted qualifier if you only need Bean<T> metadata (plain Bean<T> injection into beans is allowed with correct type rules)","Use Instance<T> or programmatic lookup instead if the goal is obtaining the bean instance"],"exampleFix":"// before\n@ApplicationScoped class Svc { @Inject @Intercepted Bean<Svc> self; }\n// after\nclass SvcInterceptor { @Inject @Intercepted Bean<Object> interceptedBean; }","handlingStrategy":"validation","validationCode":"boolean ok = java.util.Arrays.stream(MyBean.class.getDeclaredFields())\n    .noneMatch(f -> f.isAnnotationPresent(jakarta.enterprise.inject.Intercepted.class));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["@Intercepted Bean<?> belongs only in interceptor classes","Prefer plain Bean<T> or Instance<T> when metadata of the intercepted instance is not required","Keep cross-cutting metadata access inside interceptor implementations"],"tags":["cdi","arc","intercepted","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"}