quarkusio/quarkus · error · DefinitionException

Producer method return type is a parameterized type with a t

Error message

Producer method return type is a parameterized type with a type variable, its scope must be @Dependent: ${producerMethod}

What it means

A producer method whose return type is a parameterized type containing a type variable (e.g. List<T>) captures raw type info that cannot be resolved without a dependent scope. CDI therefore requires such producers to be @Dependent; ArC enforces this in Beans.createProducerMethod with a DefinitionException.

Source

Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java:193

        if (isAlternative) {
            if (priority == null) {
                priority = declaringBean.getPriority();
            }
            priority = initAlternativePriority(producerMethod, priority, stereotypes, beanDeployment);
            if (priority == null) {
                // after all attempts, priority is still null, bean will be ignored
                LOGGER.debugf(
                        "Ignoring producer method %s - declared as an @Alternative but not selected by @Priority or quarkus.arc.selected-alternatives",
                        declaringBean.getTarget().get().asClass().name() + "#" + producerMethod.name());
                return null;
            }
        }

        if (scope != null // `null` is just like `@Dependent`
                && !BuiltinScope.DEPENDENT.is(scope)
                && producerMethod.returnType().kind() == Kind.PARAMETERIZED_TYPE
                && Types.containsTypeVariable(producerMethod.returnType())) {
            throw new DefinitionException("Producer method return type is a parameterized type with a type variable, "
                    + "its scope must be @Dependent: " + producerMethod);
        }

        InterceptionProxyInfo interceptionProxy = null;
        for (MethodParameterInfo parameter : producerMethod.parameters()) {
            if (parameter.type().name().equals(DotNames.INTERCEPTION_PROXY)) {
                if (interceptionProxy != null) {
                    throw new DefinitionException(
                            "Declaring more than one InterceptionProxy parameter is invalid: " + producerMethod);
                }
                if (parameter.type().kind() != Kind.PARAMETERIZED_TYPE) {
                    throw new DefinitionException(
                            "InterceptionProxy parameter must be a parameterized type: " + producerMethod);
                }
                DotName targetClass = producerMethod.returnType().name();
                DotName bindingsSource = null;
                if (parameter.hasAnnotation(DotNames.BINDINGS_SOURCE)) {
                    Type bindingsSourceType = parameter.annotation(DotNames.BINDINGS_SOURCE).value().asClass();

View on GitHub (pinned to e1c734241f)

Solutions

  1. Annotate the producer method with @Dependent.
  2. Concretize the return type (replace the type variable with a concrete type).
  3. Return a non-parameterized type or a parameterized type without type variables (e.g. List<String>).

Example fix

// before
@ApplicationScoped
@Produces
<T> List<T> genericList() { ... }
// after
@Dependent
@Produces
<T> List<T> genericList() { ... }
Defensive patterns

Strategy: validation

Validate before calling

// Check producer method scope vs generic return type before compile
if (m.getReturnType().getTypeParameters().length > 0 ||
    Arrays.stream(m.getGenericReturnType().getTypeName().split("<")).anyMatch(s -> s.matches("[A-Z](,.*)?"))) {
    if (!m.isAnnotationPresent(Dependent.class)) {
        throw new IllegalStateException("Generic producer must be @Dependent: " + m);
    }
}

Prevention

When it happens

Trigger: A @Produces method with a normal scope (@ApplicationScoped/@RequestScoped/etc.) returns a parameterized type with a type variable, e.g. @Produces @ApplicationScoped List<T> make() on a generic class, in createProducerMethod.

Common situations: Generic producer methods on generic bean classes; upgrading strict-compatibility mode and newly failing generic producers; writing framework-ish generic factories.

Related errors


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