{"record":{"id":"856d5ebf3f790fac","repo":"apache/dubbo","slug":"unable-to-get-modulemodel-from-scopemodel","errorCode":null,"errorMessage":"Unable to get ModuleModel from ${scopeModel}","messagePattern":"Unable to get ModuleModel from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java","lineNumber":55,"sourceCode":"            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\n    public static ApplicationModel getOrDefaultApplicationModel(ScopeModel scopeModel) {\n        if (scopeModel == null) {\n            return ApplicationModel.defaultModel();\n        }\n        return getOrNullApplicationModel(scopeModel);\n    }\n\n    public static ApplicationModel getOrNullApplicationModel(ScopeModel scopeModel) {\n        if (scopeModel == null) {\n            return null;\n        }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java#L37-L73","documentation":"ScopeModelUtil.getModuleModel() narrows a ScopeModel to a ModuleModel. If the argument is non-null but is neither a ModuleModel nor null, it cannot be converted and is rejected. (Note: FrameworkModel and ApplicationModel are not auto-narrowed here — only an explicit ModuleModel or null is accepted.) The message echoes the offending model's toString for diagnosis.","triggerScenarios":"Calling ScopeModelUtil.getModuleModel(applicationModel) or getModuleModel(frameworkModel) — passing an ApplicationModel or FrameworkModel where a ModuleModel is required. Often reached when a helper that holds a generic ScopeModel forwards it to getModuleModel without first descending to the module level.","commonSituations":"Integrations that capture a ScopeModel from getOrDefault() and later assume it is module-scoped. Config holders wired with an ApplicationModel where a ModuleModel was expected. Code that worked when the default scope happened to be a module but breaks when an application/framework model is supplied.","solutions":["Pass a ModuleModel: derive it via `applicationModel.getDefaultModule()` or `moduleModel` from the correct scope before calling getModuleModel.","If you only have an ApplicationModel, use `ScopeModelUtil.getApplicationModel(appModel).getDefaultModule()` to reach the module.","Null is accepted (it resolves to the default application's default module), so prefer passing null over a wrong-typed model when you genuinely want the default."],"exampleFix":"// before (throws: appModel is not a ModuleModel)\nModuleModel m = ScopeModelUtil.getModuleModel(applicationModel);\n\n// after\nModuleModel m = ScopeModelUtil.getApplicationModel(applicationModel).getDefaultModule();","handlingStrategy":"type-guard","validationCode":"ModuleModel module;\nif (scopeModel == null) {\n    module = ApplicationModel.defaultModel().getDefaultModule();\n} else if (scopeModel instanceof ModuleModel) {\n    module = (ModuleModel) scopeModel;\n} else if (scopeModel instanceof ApplicationModel) {\n    module = ((ApplicationModel) scopeModel).getDefaultModule();\n} else {\n    throw new IllegalArgumentException(\"Cannot resolve ModuleModel from \" + scopeModel);\n}","typeGuard":"static boolean isModuleOrResolvable(ScopeModel s) {\n    return s == null || s instanceof ModuleModel || s instanceof ApplicationModel;\n}","tryCatchPattern":null,"preventionTips":["Always pass a ModuleModel (or null for the default) to getModuleModel().","Derive the module from an ApplicationModel via getDefaultModule() before calling.","Document the expected ScopeModel subtype at your API boundary."],"tags":["scope-model","module-model","type-narrowing","api-misuse"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}