{"record":{"id":"bd3beadf3deabcb9","repo":"apache/dubbo","slug":"unable-to-get-applicationmodel-from-scopemodel","errorCode":null,"errorMessage":"Unable to get ApplicationModel from ${scopeModel}","messagePattern":"Unable to get ApplicationModel from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java","lineNumber":80,"sourceCode":"\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        }\n        if (scopeModel instanceof ApplicationModel) {\n            return (ApplicationModel) scopeModel;\n        } else if (scopeModel instanceof ModuleModel) {\n            ModuleModel moduleModel = (ModuleModel) scopeModel;\n            return moduleModel.getApplicationModel();\n        } else {\n            throw new IllegalArgumentException(\"Unable to get ApplicationModel from \" + scopeModel);\n        }\n    }\n\n    public static FrameworkModel getFrameworkModel(ScopeModel scopeModel) {\n        if (scopeModel == null) {\n            return FrameworkModel.defaultModel();\n        }\n        if (scopeModel instanceof ApplicationModel) {\n            return ((ApplicationModel) scopeModel).getFrameworkModel();\n        } else if (scopeModel instanceof ModuleModel) {\n            ModuleModel moduleModel = (ModuleModel) scopeModel;\n            return moduleModel.getApplicationModel().getFrameworkModel();\n        } else if (scopeModel instanceof FrameworkModel) {\n            return (FrameworkModel) scopeModel;\n        } else {\n            throw new IllegalArgumentException(\"Unable to get FrameworkModel from \" + scopeModel);\n        }\n    }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java#L62-L98","documentation":"ScopeModelUtil.getOrNullApplicationModel() accepts only ApplicationModel and ModuleModel (descending from module to its application). Any other non-null ScopeModel — most commonly a FrameworkModel — is not convertible to an ApplicationModel and is rejected. Unlike getOrDefaultApplicationModel, this method does not fall back to a default for unknown types.","triggerScenarios":"Calling getOrNullApplicationModel(frameworkModel) or getApplicationModel(frameworkModel). A FrameworkModel sits above applications, so there is no single application to return. Also triggered by a custom ScopeModel subclass that is neither application nor module scoped.","commonSituations":"Code that obtains the framework model (e.g. via ScopeModelUtil.getFrameworkModel) and then passes it back into an application-resolution helper. Generic ScopeModel plumbing that does not distinguish framework from application scope. Custom ScopeModel subclasses from framework forks.","solutions":["Descend from FrameworkModel to an application first: use `frameworkModel.defaultApplication()` before resolving the application model.","Pass the ApplicationModel or ModuleModel you already hold instead of the FrameworkModel.","If you need a null-safe default, use getOrDefaultApplicationModel(scopeModel) which falls back to ApplicationModel.defaultModel() for null (but still throws for an unknown non-null type — narrow it first)."],"exampleFix":"// before (throws: frameworkModel is not Application/Module)\nApplicationModel app = ScopeModelUtil.getOrNullApplicationModel(frameworkModel);\n\n// after\nApplicationModel app = frameworkModel.defaultApplication();\n// or, if you already hold an app/module model, pass that directly","handlingStrategy":"type-guard","validationCode":"ApplicationModel app;\nif (scopeModel instanceof ApplicationModel) {\n    app = (ApplicationModel) scopeModel;\n} else if (scopeModel instanceof ModuleModel) {\n    app = ((ModuleModel) scopeModel).getApplicationModel();\n} else if (scopeModel instanceof FrameworkModel) {\n    app = ((FrameworkModel) scopeModel).defaultApplication();\n} else if (scopeModel == null) {\n    app = null;\n} else {\n    throw new IllegalArgumentException(\"Cannot resolve ApplicationModel from \" + scopeModel);\n}","typeGuard":"static boolean isAppResolvable(ScopeModel s) {\n    return s == null || s instanceof ApplicationModel || s instanceof ModuleModel;\n}","tryCatchPattern":null,"preventionTips":["Do not pass a FrameworkModel to application-resolution helpers; descend via defaultApplication() first.","Prefer getOrDefaultApplicationModel when a default fallback is acceptable.","Keep track of which ScopeModel subtype you hold at each layer."],"tags":["scope-model","application-model","framework-model","type-narrowing"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}