quarkusio/quarkus · error · DefinitionException
Initializer method must not have an @ObservesAsync parameter
Error message
Initializer method must not have an @ObservesAsync parameter (alternatively, async observer method must not be annotated @Inject):
What it means
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.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java:266
.collect(Collectors.toSet());
for (MethodInfo initializerMethod : initializerMethods) {
if (beanDeployment.hasAnnotation(initializerMethod, DotNames.PRODUCES)) {
throw new DefinitionException("Initializer method must not be annotated @Produces "
+ "(alternatively, producer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.DISPOSES)) {
throw new DefinitionException("Initializer method must not have a @Disposes parameter "
+ "(alternatively, disposer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES)) {
throw new DefinitionException("Initializer method must not have an @Observes parameter "
+ "(alternatively, observer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES_ASYNC)) {
throw new DefinitionException("Initializer method must not have an @ObservesAsync parameter "
+ "(alternatively, async observer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
}
validateInjections(injections, beanType);
return injections;
} else if (Kind.METHOD.equals(beanTarget.kind())) {
MethodInfo producerMethod = beanTarget.asMethod();
if (beanDeployment.hasAnnotation(producerMethod, DotNames.INJECT)) {
throw new DefinitionException("Producer method must not be annotated @Inject "
+ "(alternatively, initializer method must not be annotated @Produces): "
+ producerMethod);
}
if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.DISPOSES)) {
throw new DefinitionException("Producer method must not have a @Disposes parameter "
+ "(alternatively, disposer method must not be annotated @Produces): "
+ producerMethod);View on GitHub (pinned to e1c734241f)
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
Example fix
// before
@Inject
void init(@ObservesAsync TaskEvent e) { handle(e); }
// after
@Inject
void init() { }
void onTask(@ObservesAsync TaskEvent e) { handle(e); } Defensive patterns
Strategy: validation
Validate before calling
void checkInitializer(Method m) {
if (!m.isAnnotationPresent(jakarta.inject.Inject.class)) return;
for (var p : m.getParameters()) {
if (p.isAnnotationPresent(jakarta.enterprise.event.ObservesAsync.class)) {
throw new IllegalStateException("@ObservesAsync on initializer param: " + m);
}
}
} Prevention
- 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
When it happens
Trigger: Declaring @Inject void init(@ObservesAsync MyEvent e) in a bean; detected by Annotations.hasParameterAnnotation(initializerMethod, DotNames.OBSERVES_ASYNC) in forBean.
Common situations: 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.
Related errors
- Bean constructor must not have an @ObservesAsync parameter:
- Initializer method must not have a @Disposes parameter (alte
- Initializer method must not have an @Observes parameter (alt
- Bean constructor must not have a @Disposes parameter:
- Bean constructor must not have an @Observes parameter:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/431589dc0bf0b531.
Report an issue: GitHub.