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

  1. Split into two methods: one observer with @Observes, one disposer with @Disposes
  2. Remove the @Observes parameter from the disposer
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/f166f4dd6e293150. Report an issue: GitHub.