{"record":{"id":"18a21374d6c488bf","repo":"quarkusio/quarkus","slug":"producer-field-type-is-a-parameterized-type-with-a","errorCode":null,"errorMessage":"Producer field type is a parameterized type with a type variable, its scope must be @Dependent: ${producerField}","messagePattern":"Producer field 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":333,"sourceCode":"        if (isAlternative) {\n            if (priority == null) {\n                priority = declaringBean.getPriority();\n            }\n            priority = initAlternativePriority(producerField, priority, stereotypes, beanDeployment);\n            // after all attempts, priority is still null\n            if (priority == null) {\n                LOGGER.debugf(\n                        \"Ignoring producer field %s - declared as an @Alternative but not selected by @Priority or quarkus.arc.selected-alternatives\",\n                        producerField);\n                return null;\n            }\n        }\n\n        if (scope != null // `null` is just like `@Dependent`\n                && !BuiltinScope.DEPENDENT.is(scope)\n                && producerField.type().kind() == Kind.PARAMETERIZED_TYPE\n                && Types.containsTypeVariable(producerField.type())) {\n            throw new DefinitionException(\"Producer field type is a parameterized type with a type variable, \"\n                    + \"its scope must be @Dependent: \" + producerField);\n        }\n\n        BeanInfo bean = new BeanInfo(producerField, beanDeployment, scope, typeClosure.types(), qualifiers,\n                Collections.emptyList(),\n                declaringBean, disposer, isAlternative, stereotypes, name, isDefaultBean, null, priority,\n                typeClosure.unrestrictedTypes(), null);\n        return bean;\n    }\n\n    private static AnnotationInstance normalizedNamedQualifier(String defaultedName, AnnotationInstance originalAnnotation) {\n        // Replace @Named(\"\") with @Named(\"foo\")\n        // This is not explicitly defined by the spec but better align with the RI behavior\n        return AnnotationInstance.create(DotNames.NAMED, originalAnnotation.target(),\n                Collections.singletonList(AnnotationValue.createStringValue(\"value\", defaultedName)));\n    }\n\n    private static DefinitionException multipleScopesFound(String baseMessage, List<ScopeInfo> scopes) {","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java#L315-L351","documentation":"A producer field whose type is a parameterized type containing a type variable (e.g. Foo<T>) can only be safely resolved for @Dependent scope. Normal scopes require a proxyable, fully-resolvable bean type, so any other scope triggers this DefinitionException.","triggerScenarios":"Beans.createProducerField sees a producer field with a non-null scope that is not @Dependent, whose declared type kind is PARAMETERIZED_TYPE and Types.containsTypeVariable() is true.","commonSituations":"Annotating a generic producer field like `Foo<T> foo` with @ApplicationScoped; porting a generic class to CDI without realizing the producer field keeps the type variable; after upgrading Quarkus which enforces this rule more strictly.","solutions":["Change the producer field's scope to @Dependent","Replace the type variable with a concrete type in the producer field declaration","Move the production into a producer method that resolves the type variable from the declaring bean's own parameter"],"exampleFix":"// before\n@ApplicationScoped\n@Produces\nFoo<T> foo;\n// after\n@Dependent\n@Produces\nFoo<T> foo;","handlingStrategy":"validation","validationCode":"// check a producer field before compiling\nboolean genericParam = field.type().kind() == org.jboss.jandex.Type.Kind.PARAMETERIZED_TYPE\n        && Types.containsTypeVariable(field.type());\nif (genericParam && !field.hasAnnotation(DotNames.DEPENDENT)) {\n    // fix: annotate the field with @Dependent\n}","typeGuard":null,"tryCatchPattern":"try {\n    quarkusBuild.start();\n} catch (DefinitionException e) {\n    if (e.getMessage().contains(\"its scope must be @Dependent\")) {\n        logger.errorf(\"Make the generic producer @Dependent: %s\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Pair any parameterized type with a type variable producer with @Dependent","Prefer producer methods over producer fields for generic types","Keep scope annotations minimal on generic classes"],"tags":["cdi","arc","producer","generics","scopes"],"backgroundTag":"generic-producer-scope-must-be-dependent","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}