quarkusio/quarkus · error · DefinitionException
Disposer method must not have an @Observes parameter (altern
Error message
Disposer method must not have an @Observes parameter (alternatively, observer method must not have a @Disposes parameter):
What it means
Build-time CDI definition error from Injection.forDisposer: the method with a @Disposes parameter also has an @Observes parameter, so it would be both an observer and a disposer, which the CDI spec disallows. The offending method appears after the colon.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java:414
}
return injections;
}
static Injection forDisposer(MethodInfo disposerMethod, ClassInfo beanClass, BeanDeployment beanDeployment,
InjectionPointModifier transformer) {
if (beanDeployment.hasAnnotation(disposerMethod, DotNames.INJECT)) {
throw new DefinitionException("Disposer method must not be annotated @Inject "
+ "(alternatively, initializer method must not have a @Disposes parameter): "
+ disposerMethod);
}
if (beanDeployment.hasAnnotation(disposerMethod, DotNames.PRODUCES)) {
throw new DefinitionException("Disposer method must not be annotated @Produces "
+ "(alternatively, producer method must not have a @Disposes parameter): "
+ disposerMethod);
}
if (Annotations.hasParameterAnnotation(beanDeployment, disposerMethod, DotNames.OBSERVES)) {
throw new DefinitionException("Disposer method must not have an @Observes parameter "
+ "(alternatively, observer method must not have a @Disposes parameter): "
+ disposerMethod);
}
if (Annotations.hasParameterAnnotation(beanDeployment, disposerMethod, DotNames.OBSERVES_ASYNC)) {
throw new DefinitionException("Disposer method must not have an @ObservesAsync parameter "
+ "(alternatively, async observer method must not have a @Disposes parameter): "
+ disposerMethod);
}
if (Annotations.getParameterAnnotations(beanDeployment, disposerMethod)
.stream()
.filter(it -> DotNames.DISPOSES.equals(it.name()))
.count() > 1) {
throw new DefinitionException("Disposer method must not have more than 1 @Disposes parameter: "
+ disposerMethod);
}
Injection injection = new Injection(disposerMethod,
InjectionPointInfo.fromMethod(disposerMethod, beanClass, beanDeployment,View on GitHub (pinned to e1c734241f)
Solutions
- Split into two methods: one observer with @Observes, one disposer with @Disposes
- Remove the @Observes parameter from the disposer
- Remove the @Disposes parameter if the method was meant to be an observer
Example fix
// before
void both(@Observes Ev e, @Disposes Widget w) {}
// after
void observe(@Observes Ev e) {}
void dispose(@Disposes Widget w) {} Defensive patterns
Strategy: validation
Validate before calling
for (Method m : MyClass.class.getDeclaredMethods()) {
boolean hasDisposes = java.util.Arrays.stream(m.getParameterAnnotations())
.flatMap(java.util.Arrays::stream).anyMatch(a -> a.annotationType().getSimpleName().equals("Disposes"));
boolean hasObserves = java.util.Arrays.stream(m.getParameterAnnotations())
.flatMap(java.util.Arrays::stream).anyMatch(a -> a.annotationType().getSimpleName().equals("Observes"));
if (hasDisposes && hasObserves) throw new IllegalStateException("Observer+disposer: " + m);
} Prevention
- One role per method: observer or disposer, never both
- Audit methods with multiple special parameters (@Observes, @Disposes, @Produces)
When it happens
Trigger: Declaring a method with both a @Disposes parameter and an @Observes parameter; detected in Injection.forDisposer.
Common situations: Mixing lifecycle roles on a single method after refactoring; copy-pasting observer signatures onto disposers.
Related errors
- Disposer method must not have an @ObservesAsync parameter (a
- Multiple disposed parameters found for ${disposerMethod}
- Producer method must not have an @ObservesAsync parameter (a
- Disposer method must not be annotated @Inject (alternatively
- Disposer method must not be annotated @Produces (alternative
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/f166f4dd6e293150.
Report an issue: GitHub.