{"record":{"id":"36471e7cea354942","repo":"quarkusio/quarkus","slug":"decorator-declares-an-observer-method-decorator","errorCode":null,"errorMessage":"Decorator declares an observer method: ${decoratorClass}","messagePattern":"Decorator declares an observer method: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Decorators.java","lineNumber":171,"sourceCode":"        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            }\n\n            DotName superClass = aClass.superName();\n            aClass = superClass != null && !superClass.equals(DotNames.OBJECT)\n                    ? getClassByName(beanDeployment.getBeanArchiveIndex(), superClass)\n                    : null;\n        }\n    }","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Decorators.java#L153-L189","documentation":"Build-time CDI definition error: a method in the decorator's hierarchy (checked via the annotation store for parameter annotations) carries an @Observes parameter. Decorators cannot host observer methods per the CDI spec, so the deployment is rejected with the decorator class named.","triggerScenarios":"A @Decorator class has a method with an @Observes-annotated parameter, detected while validating decorator fields and methods.","commonSituations":"Adding event observation to an existing decorator; class converted from a regular bean (that observed events) into a decorator without removing the observer; copy-paste of observer code.","solutions":["Remove the @Observes method from the decorator.","Move observation into a separate @ApplicationScoped observer bean.","If both behaviors are needed, keep the observer bean and the decorator as distinct components.","Check inherited methods — the scan covers superclasses."],"exampleFix":"// before\n@Decorator\npublic class D implements Greeter {\n    void onStart(@Observes StartupEvent e) { }\n}\n\n// after\n@Decorator\npublic class D implements Greeter { /* observer moved to a separate bean */ }","handlingStrategy":"validation","validationCode":"if (decoratorClass.getAnnotation(jakarta.decorator.Decorator.class) != null)\n    for (Method m : decoratorClass.getMethods())\n        if (m.isAnnotationPresent(jakarta.enterprise.event.Observes.class))\n            throw new IllegalStateException(\"Decorator cannot declare observer: \" + m);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place observers in dedicated observer beans, separate from decorators.","When converting a bean into a decorator, strip all @Observes methods first."],"tags":["cdi","decorator","observer","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"}