apache/dubbo · error · IllegalArgumentException
Unable to get FrameworkModel from ${scopeModel}
Error message
Unable to get FrameworkModel from ${scopeModel} What it means
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.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java:96
return moduleModel.getApplicationModel();
} else {
throw new IllegalArgumentException("Unable to get ApplicationModel from " + scopeModel);
}
}
public static FrameworkModel getFrameworkModel(ScopeModel scopeModel) {
if (scopeModel == null) {
return FrameworkModel.defaultModel();
}
if (scopeModel instanceof ApplicationModel) {
return ((ApplicationModel) scopeModel).getFrameworkModel();
} else if (scopeModel instanceof ModuleModel) {
ModuleModel moduleModel = (ModuleModel) scopeModel;
return moduleModel.getApplicationModel().getFrameworkModel();
} else if (scopeModel instanceof FrameworkModel) {
return (FrameworkModel) scopeModel;
} else {
throw new IllegalArgumentException("Unable to get FrameworkModel from " + scopeModel);
}
}
public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> type, ScopeModel scopeModel) {
if (scopeModel != null) {
return scopeModel.getExtensionLoader(type);
} else {
SPI spi = type.getAnnotation(SPI.class);
if (spi == null) {
throw new IllegalArgumentException("SPI annotation not found for class: " + type.getName());
}
switch (spi.scope()) {
case FRAMEWORK:
return FrameworkModel.defaultModel().getExtensionLoader(type);
case APPLICATION:
return ApplicationModel.defaultModel().getExtensionLoader(type);
case MODULE:
return ApplicationModel.defaultModel().getDefaultModule().getExtensionLoader(type);View on GitHub (pinned to 3a3043227f)
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.
Example fix
// before (throws: custom ScopeModel subclass) FrameworkModel fm = ScopeModelUtil.getFrameworkModel(customScope); // after FrameworkModel fm = ScopeModelUtil.getFrameworkModel(customScope.getApplicationModel()); // or simply FrameworkModel fm = FrameworkModel.defaultModel();
Defensive patterns
Strategy: type-guard
Validate before calling
FrameworkModel fm;
if (scopeModel == null) {
fm = FrameworkModel.defaultModel();
} else if (scopeModel instanceof FrameworkModel) {
fm = (FrameworkModel) scopeModel;
} else if (scopeModel instanceof ApplicationModel) {
fm = ((ApplicationModel) scopeModel).getFrameworkModel();
} else if (scopeModel instanceof ModuleModel) {
fm = ((ModuleModel) scopeModel).getApplicationModel().getFrameworkModel();
} else {
throw new IllegalArgumentException("Cannot resolve FrameworkModel from " + scopeModel);
} Type guard
static boolean isFrameworkResolvable(ScopeModel s) {
return s == null || s instanceof FrameworkModel
|| s instanceof ApplicationModel || s instanceof ModuleModel;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to get ApplicationModel from ${scopeModel}
- Environment is inaccessible for FrameworkModel
- Unable to get ModuleModel from ${scopeModel}
- ExtensionLoader for [${type}] is not found
- setScopeModel is forbidden for ServiceAddressURL
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/540a80b5e8a4f3eb.
Report an issue: GitHub.