{"record":{"id":"e940b0ad2d92b4f5","repo":"quarkusio/quarkus","slug":"producer-method-return-type-is-a-parameterized-typ","errorCode":null,"errorMessage":"Producer method return type is a parameterized type with a type variable, its scope must be @Dependent: ${producerMethod}","messagePattern":"Producer method return type is a parameterized type with a type variable, its scope must be @Dependent: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java","lineNumber":193,"sourceCode":"        if (isAlternative) {\n            if (priority == null) {\n                priority = declaringBean.getPriority();\n            }\n            priority = initAlternativePriority(producerMethod, priority, stereotypes, beanDeployment);\n            if (priority == null) {\n                // after all attempts, priority is still null, bean will be ignored\n                LOGGER.debugf(\n                        \"Ignoring producer method %s - declared as an @Alternative but not selected by @Priority or quarkus.arc.selected-alternatives\",\n                        declaringBean.getTarget().get().asClass().name() + \"#\" + producerMethod.name());\n                return null;\n            }\n        }\n\n        if (scope != null // `null` is just like `@Dependent`\n                && !BuiltinScope.DEPENDENT.is(scope)\n                && producerMethod.returnType().kind() == Kind.PARAMETERIZED_TYPE\n                && Types.containsTypeVariable(producerMethod.returnType())) {\n            throw new DefinitionException(\"Producer method return type is a parameterized type with a type variable, \"\n                    + \"its scope must be @Dependent: \" + producerMethod);\n        }\n\n        InterceptionProxyInfo interceptionProxy = null;\n        for (MethodParameterInfo parameter : producerMethod.parameters()) {\n            if (parameter.type().name().equals(DotNames.INTERCEPTION_PROXY)) {\n                if (interceptionProxy != null) {\n                    throw new DefinitionException(\n                            \"Declaring more than one InterceptionProxy parameter is invalid: \" + producerMethod);\n                }\n                if (parameter.type().kind() != Kind.PARAMETERIZED_TYPE) {\n                    throw new DefinitionException(\n                            \"InterceptionProxy parameter must be a parameterized type: \" + producerMethod);\n                }\n                DotName targetClass = producerMethod.returnType().name();\n                DotName bindingsSource = null;\n                if (parameter.hasAnnotation(DotNames.BINDINGS_SOURCE)) {\n                    Type bindingsSourceType = parameter.annotation(DotNames.BINDINGS_SOURCE).value().asClass();","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java#L175-L211","documentation":"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.","triggerScenarios":"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.","commonSituations":"Generic producer methods on generic bean classes; upgrading strict-compatibility mode and newly failing generic producers; writing framework-ish generic factories.","solutions":["Annotate the producer method with @Dependent.","Concretize the return type (replace the type variable with a concrete type).","Return a non-parameterized type or a parameterized type without type variables (e.g. List<String>)."],"exampleFix":"// before\n@ApplicationScoped\n@Produces\n<T> List<T> genericList() { ... }\n// after\n@Dependent\n@Produces\n<T> List<T> genericList() { ... }","handlingStrategy":"validation","validationCode":"// Check producer method scope vs generic return type before compile\nif (m.getReturnType().getTypeParameters().length > 0 ||\n    Arrays.stream(m.getGenericReturnType().getTypeName().split(\"<\")).anyMatch(s -> s.matches(\"[A-Z](,.*)?\"))) {\n    if (!m.isAnnotationPresent(Dependent.class)) {\n        throw new IllegalStateException(\"Generic producer must be @Dependent: \" + m);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default generic producers to @Dependent","Avoid type variables in producer return types; use concrete types","Enable strict-compatibility in CI to catch these early"],"tags":["cdi","quarkus-arc","producer-method","generics","scope"],"backgroundTag":"generic-producer-must-be-dependent","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}