quarkusio/quarkus · error · DefinitionException
Producer method must not have an @Observes parameter (altern
Error message
Producer method must not have an @Observes parameter (alternatively, observer method must not be annotated @Produces):
What it means
ArC throws this DefinitionException when a producer method declares a parameter annotated @Observes, or an observer method is annotated @Produces. Observer parameters are exclusive to observer methods; producer methods only accept plain injection parameters. forBean's METHOD branch validates producer parameters against OBSERVES.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java:287
}
}
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);
}
if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.OBSERVES)) {
throw new DefinitionException("Producer method must not have an @Observes parameter "
+ "(alternatively, observer method must not be annotated @Produces): "
+ producerMethod);
}
if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.OBSERVES_ASYNC)) {
throw new DefinitionException("Producer method must not have an @ObservesAsync parameter "
+ "(alternatively, async observer method must not be annotated @Produces): "
+ producerMethod);
}
if (producerMethod.parameterTypes().isEmpty()) {
return Collections.emptyList();
}
// All parameters are injection points
List<Injection> injections = Collections.singletonList(new Injection(producerMethod,
InjectionPointInfo.fromMethod(producerMethod, declaringBean.getImplClazz(), beanDeployment, transformer)));
validateInjections(injections, beanType);
return injections;
}View on GitHub (pinned to e1c734241f)
Solutions
- Remove @Observes from the producer method parameter
- Add a dedicated observer method in the bean if event handling is needed
- Pass any required dependencies as plain producer parameters (injection points)
- Rebuild; failure occurs during Quarkus augmentation
Example fix
// before
@Produces
State state(@Observes RefreshEvent e) { return compute(); }
// after
@Produces
State state() { return compute(); }
void onRefresh(@Observes RefreshEvent e) { refresh(); } Defensive patterns
Strategy: validation
Validate before calling
void checkProducer(Method m) {
if (!m.isAnnotationPresent(jakarta.enterprise.inject.Produces.class)) return;
for (var p : m.getParameters()) {
if (p.isAnnotationPresent(jakarta.enterprise.event.Observes.class)) {
throw new IllegalStateException("@Observes on producer param: " + m);
}
}
} Prevention
- Observer and producer roles must live in separate methods
- Producer parameters are injection points only — no event annotations
- Handle events with dedicated @Observes methods in the same bean
- Verify annotations after refactoring event listeners into producer classes
When it happens
Trigger: Declaring @Produces Foo produce(@Observes MyEvent e); caught by Annotations.hasParameterAnnotation(producerMethod, DotNames.OBSERVES) in forBean.
Common situations: Combining event-driven production with the producer API; copy-paste from an observer method; attempting lazy/event-based bean creation which CDI does not support via @Observes on producers.
Related errors
- Bean constructor must not have an @Observes parameter:
- Initializer method must not have an @Observes parameter (alt
- Producer method must not be annotated @Inject (alternatively
- Producer method must not have a @Disposes parameter (alterna
- Bean constructor must not have a @Disposes parameter:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/988636aedf3ec78e.
Report an issue: GitHub.