{"record":{"id":"bc8f2118a1ba13c9","repo":"quarkusio/quarkus","slug":"different-scopes-defined-for-target-scopes","errorCode":null,"errorMessage":"Different scopes defined for: ${target}; scopes: ${scopes}","messagePattern":"Different scopes defined for: (.+?); scopes: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java","lineNumber":1080,"sourceCode":"                boolean inherited = clazz.hasDeclaredAnnotation(DotNames.INHERITED);\n                if (clazz.hasDeclaredAnnotation(DotNames.SCOPE)) {\n                    return new ScopeInfo(scopeAnnotationName, false, inherited);\n                } else if (clazz.hasDeclaredAnnotation(DotNames.NORMAL_SCOPE)) {\n                    return new ScopeInfo(scopeAnnotationName, true, inherited);\n                }\n            }\n        }\n        return null;\n    }\n\n    static ScopeInfo getValidScope(Set<ScopeInfo> scopes, AnnotationTarget target) {\n        switch (scopes.size()) {\n            case 0:\n                return null;\n            case 1:\n                return scopes.iterator().next();\n            default:\n                throw new DefinitionException(\n                        \"Different scopes defined for: \" + target + \"; scopes: \" + scopes.stream().map(ScopeInfo::getDotName)\n                                .map(DotName::toString).collect(Collectors.joining(\", \")));\n        }\n    }\n\n    record BeanDiscoveryResult(List<BeanInfo> beans, List<SkippedClass> skippedClasses) {\n    }\n\n    /**\n     * A class found during discovery but skipped for a specific reason.\n     */\n    record SkippedClass(ClassInfo clazz, SkippedReason reason) {\n    }\n\n    enum SkippedReason {\n        EXCLUDED_TYPE,\n        VETOED,\n        NO_BEAN_DEF_ANNOTATION,","sourceCodeStart":1062,"sourceCodeEnd":1098,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java#L1062-L1098","documentation":"When computing a bean's scope, Arc collects scope annotations from the class, stereotypes, and producer elements. If more than one distinct scope is found, the resolution is ambiguous and Arc throws DefinitionException listing the target and all conflicting scopes. CDI allows at most one scope per bean (plus @Dependent implicit).","triggerScenarios":"A bean class annotated with, e.g., @ApplicationScoped and also carrying a stereotype that declares @RequestScoped; or a producer method whose scope conflicts with its declaring class's stereotype scope without explicit override.","commonSituations":"Applying a stereotype that carries a scope to a class that also declares its own scope; stacking multiple stereotypes each with different scopes; copy-paste annotations after refactoring.","solutions":["Remove one of the conflicting scope annotations so only a single scope remains","Remove the scope from the stereotype (or from the bean class) so they agree","If overriding is intended, ensure the direct scope annotation takes precedence per CDI rules (a stereotype scope can be overridden by an explicit scope on the bean — re-check that the stereotype is actually applied where you think)","Split the stereotype into two if some users need a different scope"],"exampleFix":"// before\n@ApplicationScoped @MyRequestScopedStereotype class Foo {}\n// after\n@MyRequestScopedStereotype class Foo {} // stereotype supplies the single scope","handlingStrategy":"validation","validationCode":"Set<DotName> scopes = new HashSet<>();\nif (clazz declaredScope != null) scopes.add(declaredScope);\nstereotypes.stream().map(BeanDeployment::stereotypeScope).filter(Objects::nonNull).forEach(scopes::add);\nif (scopes.size() > 1) throw new IllegalStateException(\"Conflicting scopes: \" + scopes);","typeGuard":null,"tryCatchPattern":"try { deployment.init(); }\ncatch (DefinitionException e) { log.error(\"Conflicting scopes on \" + target + \" — keep one scope only\"); throw e; }","preventionTips":["Don't declare an explicit scope on beans that use scope-carrying stereotypes","Ensure all stereotypes applied to a class share the same scope","Audit stacked stereotypes for scope conflicts after refactors"],"tags":["cdi","scope","stereotype","definition-error","arc"],"backgroundTag":"conflicting-scope-annotations","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}