{"record":{"id":"56837512e55426ee","repo":"quarkusio/quarkus","slug":"declaring-class-of-a-managed-bean-is-generic-its","errorCode":null,"errorMessage":"Declaring class of a managed bean is generic, its scope must be @Dependent: ${beanClass}","messagePattern":"Declaring class of a managed bean is generic, 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":1401,"sourceCode":"            // 2. Stereotype scope\n            // 3. Bean defining annotation default scope\n            ScopeInfo scope;\n            if (scopes.isEmpty()) {\n                // Inheritance of type-level metadata: \"A scope type explicitly declared by X and inherited by Y from X takes precedence over default scopes of stereotypes declared or inherited by Y.\"\n                scope = inheritScope(beanClass, beanDeployment);\n                if (scope == null) {\n                    scope = initStereotypeScope(stereotypes, beanClass, beanDeployment);\n                    if (scope == null) {\n                        scope = initBeanDefiningAnnotationScope(beanDefiningAnnotationScopes, beanClass);\n                    }\n                }\n            } else {\n                scope = scopes.get(0);\n            }\n            if (scope != null // `null` is just like `@Dependent`\n                    && !BuiltinScope.DEPENDENT.is(scope)\n                    && !beanClass.typeParameters().isEmpty()) {\n                throw new DefinitionException(\n                        \"Declaring class of a managed bean is generic, its scope must be @Dependent: \" + beanClass);\n            }\n            if (!isAlternative) {\n                isAlternative = initStereotypeAlternative(stereotypes, beanDeployment);\n            }\n            if (name == null) {\n                name = initStereotypeName(stereotypes, beanClass, beanDeployment);\n            }\n\n            if (isAlternative) {\n                priority = initAlternativePriority(beanClass, priority, stereotypes, beanDeployment);\n                if (priority == null) {\n                    // after all attempts, priority is still null, bean will be ignored\n                    LOGGER.debugf(\n                            \"Ignoring bean defined via %s - declared as an @Alternative but not selected by @Priority or quarkus.arc.selected-alternatives\",\n                            beanClass.name());\n                    return null;\n                }","sourceCodeStart":1383,"sourceCodeEnd":1419,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java#L1383-L1419","documentation":"A managed bean whose declaring class is generic (declares type parameters) can only be instantiated with properly resolvable type arguments under @Dependent scope. Any other scope requires proxying, which cannot work with unresolved type variables, so ArC throws a DefinitionException.","triggerScenarios":"Beans (public managed-bean creation) computes the bean's scope; scope is non-null and not @Dependent while beanClass.typeParameters() is non-empty.","commonSituations":"Adding @ApplicationScoped to a generic class like Repository<T>; upgrading Quarkus/ArC where this CDI rule became enforced; copy-pasting scope annotations onto generic base classes.","solutions":["Make the bean class @Dependent (or remove the scope annotation)","Remove the type parameters by making the class concrete with specific types","Introduce a non-generic producer or a concrete subclass per type instantiation"],"exampleFix":"// before\n@ApplicationScoped\nclass Repo<T> { }\n// after\n@Dependent\nclass Repo<T> { }","handlingStrategy":"validation","validationCode":"// before annotating a generic class with a normal scope\nif (!clazz.typeParameters().isEmpty()\n        && scope != null && !BuiltinScope.DEPENDENT.is(scope)) {\n    // fix: make the class @Dependent or remove type params\n}","typeGuard":null,"tryCatchPattern":"try {\n    quarkusBuild.start();\n} catch (DefinitionException e) {\n    if (e.getMessage().contains(\"generic, its scope must be @Dependent\")) {\n        logger.errorf(\"Make generic bean class @Dependent: %s\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Keep generic bean classes @Dependent","Prefer producers or concrete subclasses for normal-scoped beans","Check for type parameters before adding @ApplicationScoped/@RequestScoped"],"tags":["cdi","arc","generics","scopes","bean-definition"],"backgroundTag":"generic-bean-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"}