{"record":{"id":"431589dc0bf0b531","repo":"quarkusio/quarkus","slug":"initializer-method-must-not-have-an-observesasync","errorCode":null,"errorMessage":"Initializer method must not have an @ObservesAsync parameter (alternatively, async observer method must not be annotated @Inject): ","messagePattern":"Initializer method must not have an @ObservesAsync parameter \\(alternatively, async 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":266,"sourceCode":"                    .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);\n            }\n            if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.DISPOSES)) {\n                throw new DefinitionException(\"Producer method must not have a @Disposes parameter \"\n                        + \"(alternatively, disposer method must not be annotated @Produces): \"\n                        + producerMethod);","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L248-L284","documentation":"ArC throws this DefinitionException when an initializer (@Inject) method has a parameter annotated @ObservesAsync, or an async observer method is annotated @Inject. @ObservesAsync parameters are only valid on async observer methods; initializer methods must only declare plain injection points. forBean enforces this while iterating initializer methods.","triggerScenarios":"Declaring @Inject void init(@ObservesAsync MyEvent e) in a bean; detected by Annotations.hasParameterAnnotation(initializerMethod, DotNames.OBSERVES_ASYNC) in forBean.","commonSituations":"Attempting async event handling during bean initialization; copy-paste from an async observer into an init method; mixing up @Observes and @ObservesAsync when refactoring listeners into beans.","solutions":["Remove @ObservesAsync from the initializer parameter","Add a separate async observer method: void onEvent(@ObservesAsync MyEvent e)","Handle initialization via a normal @Observes StartupEvent observer or an initializer without event annotations","Rebuild; validation is at Quarkus augmentation time"],"exampleFix":"// before\n@Inject\nvoid init(@ObservesAsync TaskEvent e) { handle(e); }\n\n// after\n@Inject\nvoid init() { }\n\nvoid onTask(@ObservesAsync TaskEvent e) { handle(e); }","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.ObservesAsync.class)) {\n            throw new IllegalStateException(\"@ObservesAsync on initializer param: \" + m);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep async event handling in dedicated @ObservesAsync methods","Do not mix initializer and async observer roles in one method","Audit refactors that move async listeners into beans","Compile early — the error is caught at augmentation"],"tags":["cdi","arc","observes-async","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-12T22:17:10.623Z"}