{"record":{"id":"35a213ec0b5ca97f","repo":"apache/dubbo","slug":"invalid-scope-model-expect-to-be-a-modulemodel-bu-35a213","errorCode":null,"errorMessage":"Invalid scope model, expect to be a ModuleModel but got: <scopeModel>","messagePattern":"Invalid scope model, expect to be a ModuleModel but got: <scopeModel>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java","lineNumber":131,"sourceCode":"\n    public ModuleConfig(ModuleModel moduleModel, String name) {\n        this(moduleModel);\n        setName(name);\n    }\n\n    @Override\n    protected void checkDefault() {\n        super.checkDefault();\n        // default is false\n        if (background == null) {\n            background = false;\n        }\n    }\n\n    @Override\n    protected void checkScopeModel(ScopeModel scopeModel) {\n        if (!(scopeModel instanceof ModuleModel)) {\n            throw new IllegalArgumentException(\n                    \"Invalid scope model, expect to be a ModuleModel but got: \" + scopeModel);\n        }\n    }\n\n    @Override\n    @Transient\n    public ModuleModel getScopeModel() {\n        return (ModuleModel) super.getScopeModel();\n    }\n\n    @Override\n    @Transient\n    protected ScopeModel getDefaultModel() {\n        return ApplicationModel.defaultModel().getDefaultModule();\n    }\n\n    @Parameter(key = \"module\")\n    public String getName() {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java#L113-L149","documentation":"Thrown by ModuleConfig.checkScopeModel when the assigned ScopeModel is not a ModuleModel. ModuleConfig instances must belong to a module scope, so assigning an ApplicationModel or FrameworkModel is rejected. The check runs during the scope-model validation phase of config refresh.","triggerScenarios":"Calling setScopeModel (or refresh that triggers checkScopeModel) on a ModuleConfig with a ScopeModel that is not an instance of ModuleModel, e.g. passing an ApplicationModel or FrameworkModel.","commonSituations":"Manually wiring configs across scope boundaries (e.g. grabbing applicationModel and assigning it to a module config). Misunderstanding the Dubbo scope hierarchy (FrameworkModel -> ApplicationModel -> ModuleModel). Copy-pasting scope-model assignment code between config types with different requirements.","solutions":["Pass a ModuleModel instance (e.g. applicationModel.getDefaultModule() or a newly created ModuleModel) to the ModuleConfig.","Obtain the correct scope from the owning module rather than the application or framework.","Review the ScopeModel hierarchy and use the level that matches the config type."],"exampleFix":"// before\nmoduleConfig.setScopeModel(applicationModel); // ApplicationModel, not ModuleModel\n\n// after\nmoduleConfig.setScopeModel(applicationModel.getDefaultModule());","handlingStrategy":"type-guard","validationCode":"// Validate scope before assignment\nif (!(scopeModel instanceof ModuleModel)) {\n    throw new IllegalArgumentException(\n        \"ModuleConfig requires a ModuleModel, got: \" + scopeModel);\n}\nmoduleConfig.setScopeModel(scopeModel);","typeGuard":"static boolean isModuleModelScope(ScopeModel s) {\n    return s instanceof ModuleModel;\n}","tryCatchPattern":"try {\n    moduleConfig.setScopeModel(scopeModel);\n} catch (IllegalArgumentException e) {\n    // resolve the correct scope level and retry\n    moduleConfig.setScopeModel(applicationModel.getDefaultModule());\n}","preventionTips":["Remember the scope hierarchy: FrameworkModel -> ApplicationModel -> ModuleModel; ModuleConfig needs the leaf.","Always pull the scope from the owning module, not the application/framework.","Centralize scope-model assignment in a helper that asserts the correct type."],"tags":["scope-model","config","validation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}