quarkusio/quarkus · error · DefinitionException

Disposer method must not have more than 1 @Disposes paramete

Error message

Disposer method must not have more than 1 @Disposes parameter: 

What it means

A CDI definition error thrown by the ArC processor while building injection metadata for a disposer method (Injection.forDisposer). A disposer method identifies the bean instance it cleans up via exactly one @Disposes parameter; this guard counts @Disposes-annotated parameters and fires when more than one is present, because the container cannot decide which parameter represents the disposed producer. The method itself is not otherwise invalid - only the duplicated @Disposes annotation is at fault.

Source

Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java:427

            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,
                        (annotations, position) -> annotations.stream().anyMatch(a -> a.name().equals(DotNames.DISPOSES)),
                        transformer));
        injection.injectionPoints.forEach(ipi -> validateInjections(ipi, BeanType.MANAGED_BEAN));
        return injection;
    }

    static Injection forObserver(MethodInfo observerMethod, ClassInfo beanClass, BeanDeployment beanDeployment,
            InjectionPointModifier transformer) {
        return new Injection(observerMethod, InjectionPointInfo.fromMethod(observerMethod, beanClass, beanDeployment,
                (annotations, position) -> annotations.stream()
                        .anyMatch(a -> a.name().equals(DotNames.OBSERVES) || a.name().equals(DotNames.OBSERVES_ASYNC)),
                transformer));
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Keep exactly one @Disposes parameter; remove @Disposes from the extra parameters (they become regular injection points)
  2. Split disposal logic into separate disposer methods, one per bean type

Example fix

// before
void dispose(@Disposes Widget a, @Disposes Gadget b) {}
// after
void dispose(@Disposes Widget a, Gadget b) {}
Defensive patterns

Strategy: validation

Validate before calling

for (Method m : MyClass.class.getDeclaredMethods()) {
    long count = java.util.Arrays.stream(m.getParameterAnnotations()).flatMap(java.util.Arrays::stream)
        .filter(a -> a.annotationType().getSimpleName().equals("Disposes")).count();
    if (count > 1) throw new IllegalStateException("Multiple @Disposes params: " + m);
}

Prevention

When it happens

Trigger: Declaring two or more parameters annotated @Disposes on a single disposer method; detected in Injection.forDisposer.

Common situations: Trying to dispose two beans in one method; copy-paste duplication of the @Disposes annotation across parameters.

Related errors


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