{"record":{"id":"8ce0b5f281c1fd76","repo":"apache/dubbo","slug":"invalid-scope-model-expect-to-be-a-applicationmod","errorCode":null,"errorMessage":"Invalid scope model, expect to be a ApplicationModel but got: <scopeModel>","messagePattern":"Invalid scope model, expect to be a ApplicationModel but got: <scopeModel>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java","lineNumber":458,"sourceCode":"\n    @Transient\n    protected ScopeModel getDefaultModel() {\n        return ApplicationModel.defaultModel();\n    }\n\n    public final void setScopeModel(ScopeModel scopeModel) {\n        if (scopeModel != null && this.scopeModel != scopeModel) {\n            checkScopeModel(scopeModel);\n            ScopeModel oldScopeModel = this.scopeModel;\n            this.scopeModel = scopeModel;\n            // reinitialize spi extension and change referenced config's scope model\n            this.postProcessAfterScopeModelChanged(oldScopeModel, this.scopeModel);\n        }\n    }\n\n    protected void checkScopeModel(ScopeModel scopeModel) {\n        if (!(scopeModel instanceof ApplicationModel)) {\n            throw new IllegalArgumentException(\n                    \"Invalid scope model, expect to be a ApplicationModel but got: \" + scopeModel);\n        }\n    }\n\n    /**\n     * Subclass should override this method to initialize its SPI extensions and change referenced config's scope model.\n     * <p>\n     * For example:\n     * <pre>\n     * protected void postProcessAfterScopeModelChanged() {\n     *   super.postProcessAfterScopeModelChanged();\n     *   // re-initialize spi extension\n     *   this.protocol = this.getExtensionLoader(Protocol.class).getAdaptiveExtension();\n     *   // change referenced config's scope model\n     *   if (this.providerConfig != null && this.providerConfig.getScopeModel() != scopeModel) {\n     *     this.providerConfig.setScopeModel(scopeModel);\n     *   }\n     * }","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java#L440-L476","documentation":"Thrown by AbstractConfig.checkScopeModel during setScopeModel: the argument is not an instanceof ApplicationModel. The base AbstractConfig requires an ApplicationModel-level scope. Subclasses like Module-scoped configs override checkScopeModel to allow ModuleModel, but the default rejects anything else with IllegalArgumentException.","triggerScenarios":"config.setScopeModel(someScopeModel) is called where someScopeModel is a FrameworkModel, a ModuleModel (on a config whose checkScopeModel isn't overridden to allow it), or a custom ScopeModel. Happens during explicit model assignment or when Dubbo internally propagates a model.","commonSituations":"Mixing a FrameworkModel where an ApplicationModel is expected (e.g. multi-ApplicationSet setups). Assigning a ModuleModel to a config type that only accepts ApplicationModel. Custom config subclass forgetting to override checkScopeModel when module-scoped.","solutions":["Pass an ApplicationModel instance to setScopeModel; derive one from a FrameworkModel via defaultApplicationModel().","If the config should be module-scoped, override checkScopeModel in the subclass to accept ModuleModel.","Do not setScopeModel with FrameworkModel or custom subtypes on base AbstractConfig.","After a Dubbo upgrade, re-check the ScopeModel type expected by your config wiring."],"exampleFix":"// before\nconfig.setScopeModel(moduleModel); // base AbstractConfig rejects this\n// after\n// use the application model (moduleModel.getApplicationModel())\nconfig.setScopeModel(moduleModel.getApplicationModel());","handlingStrategy":"type-guard","validationCode":"void setAppScopeModel(AbstractConfig cfg, ScopeModel m) {\n    if (!(m instanceof ApplicationModel)) {\n        throw new IllegalArgumentException(\"ApplicationModel required, got \" + m);\n    }\n    cfg.setScopeModel(m);\n}","typeGuard":"boolean isApplicationModel(ScopeModel m) { return m instanceof ApplicationModel; }","tryCatchPattern":"try {\n    config.setScopeModel(candidate);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Invalid scope model\")) { /* pass ApplicationModel instead */ }\n    throw e;\n}","preventionTips":["Resolve the ApplicationModel from whatever model you hold before setScopeModel.","If a config must be module-scoped, override checkScopeModel to accept ModuleModel.","Never pass FrameworkModel to a base AbstractConfig."],"tags":["config","scope-model","application-model","startup"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}