apache/dubbo · error · IllegalArgumentException
Unable to get ApplicationModel from ${scopeModel}
Error message
Unable to get ApplicationModel from ${scopeModel} What it means
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.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java:80
public static ApplicationModel getOrDefaultApplicationModel(ScopeModel scopeModel) {
if (scopeModel == null) {
return ApplicationModel.defaultModel();
}
return getOrNullApplicationModel(scopeModel);
}
public static ApplicationModel getOrNullApplicationModel(ScopeModel scopeModel) {
if (scopeModel == null) {
return null;
}
if (scopeModel instanceof ApplicationModel) {
return (ApplicationModel) scopeModel;
} else if (scopeModel instanceof ModuleModel) {
ModuleModel moduleModel = (ModuleModel) scopeModel;
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);
}
}View on GitHub (pinned to 3a3043227f)
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).
Example fix
// before (throws: frameworkModel is not Application/Module) ApplicationModel app = ScopeModelUtil.getOrNullApplicationModel(frameworkModel); // after ApplicationModel app = frameworkModel.defaultApplication(); // or, if you already hold an app/module model, pass that directly
Defensive patterns
Strategy: type-guard
Validate before calling
ApplicationModel app;
if (scopeModel instanceof ApplicationModel) {
app = (ApplicationModel) scopeModel;
} else if (scopeModel instanceof ModuleModel) {
app = ((ModuleModel) scopeModel).getApplicationModel();
} else if (scopeModel instanceof FrameworkModel) {
app = ((FrameworkModel) scopeModel).defaultApplication();
} else if (scopeModel == null) {
app = null;
} else {
throw new IllegalArgumentException("Cannot resolve ApplicationModel from " + scopeModel);
} Type guard
static boolean isAppResolvable(ScopeModel s) {
return s == null || s instanceof ApplicationModel || s instanceof ModuleModel;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to get FrameworkModel from ${scopeModel}
- scope model is invalid: <scopeModel>
- Invalid scope model, expect to be a ApplicationModel but got
- Environment is inaccessible for FrameworkModel
- Unable to get ModuleModel from ${scopeModel}
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/bd3beadf3deabcb9.
Report an issue: GitHub.