{"record":{"id":"2aaad08783893739","repo":"quarkusio/quarkus","slug":"initializer-method-must-not-have-an-observes-para","errorCode":null,"errorMessage":"Initializer method must not have an @Observes parameter (alternatively, observer method must not be annotated @Inject): ","messagePattern":"Initializer method must not have an @Observes parameter \\(alternatively, observer method must not be annotated @Inject\\): ","errorType":"validation","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java","lineNumber":261,"sourceCode":"\n            Set<MethodInfo> initializerMethods = injections.stream()\n                    .filter(it -> it.isMethod() && !it.isConstructor())\n                    .map(Injection::getTarget)\n                    .map(AnnotationTarget::asMethod)\n                    .collect(Collectors.toSet());\n            for (MethodInfo initializerMethod : initializerMethods) {\n                if (beanDeployment.hasAnnotation(initializerMethod, DotNames.PRODUCES)) {\n                    throw new DefinitionException(\"Initializer method must not be annotated @Produces \"\n                            + \"(alternatively, producer method must not be annotated @Inject): \"\n                            + beanTarget.asClass() + \".\" + initializerMethod.name());\n                }\n                if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.DISPOSES)) {\n                    throw new DefinitionException(\"Initializer method must not have a @Disposes parameter \"\n                            + \"(alternatively, disposer method must not be annotated @Inject): \"\n                            + beanTarget.asClass() + \".\" + initializerMethod.name());\n                }\n                if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES)) {\n                    throw new DefinitionException(\"Initializer method must not have an @Observes parameter \"\n                            + \"(alternatively, observer method must not be annotated @Inject): \"\n                            + beanTarget.asClass() + \".\" + initializerMethod.name());\n                }\n                if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES_ASYNC)) {\n                    throw new DefinitionException(\"Initializer method must not have an @ObservesAsync parameter \"\n                            + \"(alternatively, async observer method must not be annotated @Inject): \"\n                            + beanTarget.asClass() + \".\" + initializerMethod.name());\n                }\n            }\n            validateInjections(injections, beanType);\n            return injections;\n        } else if (Kind.METHOD.equals(beanTarget.kind())) {\n            MethodInfo producerMethod = beanTarget.asMethod();\n\n            if (beanDeployment.hasAnnotation(producerMethod, DotNames.INJECT)) {\n                throw new DefinitionException(\"Producer method must not be annotated @Inject \"\n                        + \"(alternatively, initializer method must not be annotated @Produces): \"\n                        + producerMethod);","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L243-L279","documentation":"ArC throws this DefinitionException when an initializer (@Inject) method declares a parameter annotated @Observes — or a plain observer method annotated @Inject. Observer methods are discovered by their @Observes annotation and must not also be initializers; forBean validates initializer methods for parameter-level @Observes.","triggerScenarios":"An @Inject initializer method whose parameter is annotated @Observes (e.g. @Inject void init(@Observes MyEvent e)); caught by hasParameterAnnotation(initializerMethod, DotNames.OBSERVES) in forBean.","commonSituations":"Trying to react to events during bean initialization via an @Inject method; refactoring a standalone observer method into a bean's initializer; generated code combining @Inject with event handlers.","solutions":["Remove @Observes from the initializer parameter and add a separate observer method","If you need startup work, observe StartupEvent in a dedicated @Observes method inside the bean","Keep the initializer for plain dependency injection only","Rebuild; failure occurs at augmentation time"],"exampleFix":"// before\n@Inject\nvoid init(@Observes StartupEvent e) { setup(); }\n\n// after\n@Inject\nvoid init() { }\n\nvoid onStart(@Observes StartupEvent e) { setup(); }","handlingStrategy":"validation","validationCode":"void checkInitializer(Method m) {\n    if (!m.isAnnotationPresent(jakarta.inject.Inject.class)) return;\n    for (var p : m.getParameters()) {\n        if (p.isAnnotationPresent(jakarta.enterprise.event.Observes.class)) {\n            throw new IllegalStateException(\"@Observes on initializer param: \" + m);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Separate initialization (@Inject) from event handling (@Observes methods)","Use a StartupEvent observer method for startup logic","Never combine @Inject with observer/disposer parameter annotations","Enable CDI validation in IDE for early feedback"],"tags":["cdi","arc","observes","initializer","bean-definition","build-time"],"backgroundTag":"cdi-bean-definition-invalid","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"}