{"record":{"id":"3f55e69064a272fc","repo":"quarkusio/quarkus","slug":"decorator-declares-a-producer-method-decoratorc","errorCode":null,"errorMessage":"Decorator declares a producer method: ${decoratorClass}","messagePattern":"Decorator declares a producer method: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Decorators.java","lineNumber":164,"sourceCode":"                    method.appendTo(message);\n                    message.append(\"\\n\");\n                }\n                throw new DefinitionException(message.toString());\n            }\n        }\n\n        checkDecoratorFieldsAndMethods(decoratorClass, beanDeployment);\n\n        return new DecoratorInfo(decoratorClass, beanDeployment, delegateInjectionPoint,\n                decoratedTypes, injections, priority);\n    }\n\n    private static void checkDecoratorFieldsAndMethods(ClassInfo decoratorClass, BeanDeployment beanDeployment) {\n        ClassInfo aClass = decoratorClass;\n        while (aClass != null) {\n            for (MethodInfo method : aClass.methods()) {\n                if (beanDeployment.hasAnnotation(method, DotNames.PRODUCES)) {\n                    throw new DefinitionException(\"Decorator declares a producer method: \" + decoratorClass);\n                }\n                // the following 3 checks rely on the annotation store returning parameter annotations for methods\n                if (beanDeployment.hasAnnotation(method, DotNames.DISPOSES)) {\n                    throw new DefinitionException(\"Decorator declares a disposer method: \" + decoratorClass);\n                }\n                if (beanDeployment.hasAnnotation(method, DotNames.OBSERVES)) {\n                    throw new DefinitionException(\"Decorator declares an observer method: \" + decoratorClass);\n                }\n                if (beanDeployment.hasAnnotation(method, DotNames.OBSERVES_ASYNC)) {\n                    throw new DefinitionException(\"Decorator declares an async observer method: \" + decoratorClass);\n                }\n            }\n\n            for (FieldInfo field : aClass.fields()) {\n                if (beanDeployment.hasAnnotation(field, DotNames.PRODUCES)) {\n                    throw new DefinitionException(\"Decorator declares a producer field: \" + decoratorClass);\n                }\n            }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Decorators.java#L146-L182","documentation":"CDI definition error thrown at build time by the ArC processor while validating a decorator class (including its superclasses): a decorator must only decorate via a @Delegate injection point, and a method annotated @Produces turns it into a producer, which the CDI spec forbids inside decorators. The offending class is the decorator named in the message.","triggerScenarios":"A class annotated @Decorator (or inheriting from one) contains a method annotated @Produces, discovered while creating the DecoratorInfo.","commonSituations":"Converting an ordinary bean that produced helper objects into a decorator without removing producer methods; copy-paste of a producer into a decorator; annotation left behind after refactor.","solutions":["Remove the @Produces method from the decorator class.","Move the producer to a separate non-decorator bean and inject it where needed.","If the class should be a producer bean, remove the @Decorator annotation and give it a proper bean-defining annotation.","Check superclasses too — the validation walks the hierarchy."],"exampleFix":"// before\n@Decorator\npublic class LoggingGreeting implements Greeter {\n    @Produces\n    Helper helper() { return new Helper(); }\n}\n\n// after\n@Decorator\npublic class LoggingGreeting implements Greeter {\n    @Inject Helper helper; // produced elsewhere\n}","handlingStrategy":"validation","validationCode":"if (decoratorClass.getAnnotation(jakarta.decorator.Decorator.class) != null)\n    for (Method m : decoratorClass.getMethods())\n        if (m.isAnnotationPresent(jakarta.enterprise.inject.Produces.class))\n            throw new IllegalStateException(\"Decorator cannot declare producer: \" + m);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mix @Decorator with @Produces methods; move producers to a dedicated bean.","Add an ArchUnit rule: classes annotated @Decorator must not contain @Produces/@Disposes/@Observes members."],"tags":["cdi","decorator","producer","illegal-annotation"],"backgroundTag":"illegal-annotation-on-decorator","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}