{"record":{"id":"540a80b5e8a4f3eb","repo":"apache/dubbo","slug":"unable-to-get-frameworkmodel-from-scopemodel","errorCode":null,"errorMessage":"Unable to get FrameworkModel from ${scopeModel}","messagePattern":"Unable to get FrameworkModel from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java","lineNumber":96,"sourceCode":"            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    }\n\n    public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> type, ScopeModel scopeModel) {\n        if (scopeModel != null) {\n            return scopeModel.getExtensionLoader(type);\n        } else {\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().getExtensionLoader(type);\n                case APPLICATION:\n                    return ApplicationModel.defaultModel().getExtensionLoader(type);\n                case MODULE:\n                    return ApplicationModel.defaultModel().getDefaultModule().getExtensionLoader(type);","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java#L78-L114","documentation":"ScopeModelUtil.getFrameworkModel() accepts ApplicationModel (ascends to its framework), ModuleModel (ascends via its application), FrameworkModel (returned as-is), or null (returns the default framework). Any other non-null ScopeModel subclass is rejected because there is no defined path from an arbitrary scope to a framework.","triggerScenarios":"Calling getFrameworkModel(someCustomScopeModel) where the argument is a non-null ScopeModel that is none of the three known subtypes. The known subtypes plus null are all handled, so this fires only for unexpected ScopeModel implementations.","commonSituations":"A framework fork or advanced integration that subclasses ScopeModel directly (rather than FrameworkModel/ApplicationModel/ModuleModel). Passing a mock ScopeModel in a test. Rare; the three built-in subtypes cover all normal Dubbo usage.","solutions":["Pass one of the built-in subtypes (FrameworkModel/ApplicationModel/ModuleModel) or null to get the default framework.","If you subclassed ScopeModel, cast/resolve to the nearest real subtype before calling getFrameworkModel.","In tests, pass a real FrameworkModel.defaultModel() or a Mockito mock of a concrete subtype rather than a bare ScopeModel."],"exampleFix":"// before (throws: custom ScopeModel subclass)\nFrameworkModel fm = ScopeModelUtil.getFrameworkModel(customScope);\n\n// after\nFrameworkModel fm = ScopeModelUtil.getFrameworkModel(customScope.getApplicationModel());\n// or simply\nFrameworkModel fm = FrameworkModel.defaultModel();","handlingStrategy":"type-guard","validationCode":"FrameworkModel fm;\nif (scopeModel == null) {\n    fm = FrameworkModel.defaultModel();\n} else if (scopeModel instanceof FrameworkModel) {\n    fm = (FrameworkModel) scopeModel;\n} else if (scopeModel instanceof ApplicationModel) {\n    fm = ((ApplicationModel) scopeModel).getFrameworkModel();\n} else if (scopeModel instanceof ModuleModel) {\n    fm = ((ModuleModel) scopeModel).getApplicationModel().getFrameworkModel();\n} else {\n    throw new IllegalArgumentException(\"Cannot resolve FrameworkModel from \" + scopeModel);\n}","typeGuard":"static boolean isFrameworkResolvable(ScopeModel s) {\n    return s == null || s instanceof FrameworkModel\n        || s instanceof ApplicationModel || s instanceof ModuleModel;\n}","tryCatchPattern":null,"preventionTips":["Pass only the built-in ScopeModel subtypes (or null) to getFrameworkModel().","In tests, use real FrameworkModel.defaultModel() or mocks of concrete subtypes, not bare ScopeModel.","Avoid subclassing ScopeModel directly; extend FrameworkModel/ApplicationModel/ModuleModel."],"tags":["scope-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"}