{"record":{"id":"9301683e15e59758","repo":"apache/dubbo","slug":"unable-to-get-default-scope-model-for-type-type","errorCode":null,"errorMessage":"Unable to get default scope model for type: ${type.getName()}","messagePattern":"Unable to get default scope model for type: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java","lineNumber":44,"sourceCode":"            return scopeModel;\n        }\n        return getDefaultScopeModel(type);\n    }\n\n    private static <T> ScopeModel getDefaultScopeModel(Class<T> type) {\n        SPI spi = type.getAnnotation(SPI.class);\n        if (spi == null) {\n            throw new IllegalArgumentException(\"SPI annotation not found for class: \" + type.getName());\n        }\n        switch (spi.scope()) {\n            case FRAMEWORK:\n                return FrameworkModel.defaultModel();\n            case APPLICATION:\n                return ApplicationModel.defaultModel();\n            case MODULE:\n                return ApplicationModel.defaultModel().getDefaultModule();\n            default:\n                throw new IllegalStateException(\"Unable to get default scope model for type: \" + type.getName());\n        }\n    }\n\n    public static ModuleModel getModuleModel(ScopeModel scopeModel) {\n        if (scopeModel == null) {\n            return ApplicationModel.defaultModel().getDefaultModule();\n        }\n        if (scopeModel instanceof ModuleModel) {\n            return (ModuleModel) scopeModel;\n        } else {\n            throw new IllegalArgumentException(\"Unable to get ModuleModel from \" + scopeModel);\n        }\n    }\n\n    public static ApplicationModel getApplicationModel(ScopeModel scopeModel) {\n        return getOrDefaultApplicationModel(scopeModel);\n    }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java#L26-L62","documentation":"The default branch of the switch over spi.scope() in getDefaultScopeModel(). SPI.Scope is a fixed enum (FRAMEWORK, APPLICATION, MODULE), so under normal conditions every value is handled and this branch is unreachable. Reaching it implies the enum was extended at runtime, a future-incompatible Dubbo version mismatch, or bytecode manipulation that introduced a new scope constant not understood by this build.","triggerScenarios":"A version of dubbo-common where SPI.Scope has an enum constant that this ScopeModelUtil switch does not case on (mixed-version jars on the classpath). Theoretically reachable via reflective enum injection. Practically a defensive guard against an internal contract change.","commonSituations":"Dependency conflicts: a newer dubbo-spi/extension module defines a new SPI.Scope value but dubbo-common is an older version. Shaded/relocated Dubbo jars from different vendors on the same classpath. Custom forks that add scope enum values without updating ScopeModelUtil.","solutions":["Align all Dubbo module versions to the same release (use a BOM / dependencyManagement to pin dubbo-bom).","Run `mvn dependency:tree` (or gradle equivalent) and eliminate mismatched dubbo-* versions.","If you forked Dubbo and added an SPI.Scope value, add a matching case to this switch.","Upgrade dubbo-common to match the version that introduced the new scope constant."],"exampleFix":"// not a user-code fix; resolve dependency versions\n// before (mismatched): dubbo-common 3.0.x, dubbo-spi 3.1.x with new scope\n// after: pin all via BOM\n<dependencyManagement>\n  <dependencies>\n    <dependency>\n      <groupId>org.apache.dubbo</groupId>\n      <artifactId>dubbo-bom</artifactId>\n      <version>3.1.0</version>\n      <type>pom</type>\n      <scope>import</scope>\n    </dependency>\n  </dependencies>\n</dependencyManagement>","handlingStrategy":"validation","validationCode":"// Defensive: verify the enum values this build knows match the runtime enum.\nSet<String> known = Set.of(\"FRAMEWORK\", \"APPLICATION\", \"MODULE\");\nfor (SPI.Scope s : SPI.Scope.values()) {\n    if (!known.contains(s.name())) {\n        throw new IllegalStateException(\"Unsupported SPI.Scope \" + s + \" — Dubbo version mismatch\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin all dubbo-* artifacts to one version via dubbo-bom.","Check dependency:tree for divergent Dubbo versions before release.","Avoid mixing shaded Dubbo jars from different vendors."],"tags":["spi","scope-model","version-conflict","dependency-management"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}