apache/dubbo · error · IllegalArgumentException
Invalid scope model, expect to be a ModuleModel but got: <sc
Error message
Invalid scope model, expect to be a ModuleModel but got: <scopeModel>
What it means
Thrown by ModuleConfig.checkScopeModel when the assigned ScopeModel is not a ModuleModel. ModuleConfig instances must belong to a module scope, so assigning an ApplicationModel or FrameworkModel is rejected. The check runs during the scope-model validation phase of config refresh.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java:131
public ModuleConfig(ModuleModel moduleModel, String name) {
this(moduleModel);
setName(name);
}
@Override
protected void checkDefault() {
super.checkDefault();
// default is false
if (background == null) {
background = false;
}
}
@Override
protected void checkScopeModel(ScopeModel scopeModel) {
if (!(scopeModel instanceof ModuleModel)) {
throw new IllegalArgumentException(
"Invalid scope model, expect to be a ModuleModel but got: " + scopeModel);
}
}
@Override
@Transient
public ModuleModel getScopeModel() {
return (ModuleModel) super.getScopeModel();
}
@Override
@Transient
protected ScopeModel getDefaultModel() {
return ApplicationModel.defaultModel().getDefaultModule();
}
@Parameter(key = "module")
public String getName() {View on GitHub (pinned to 3a3043227f)
Solutions
- Pass a ModuleModel instance (e.g. applicationModel.getDefaultModule() or a newly created ModuleModel) to the ModuleConfig.
- Obtain the correct scope from the owning module rather than the application or framework.
- Review the ScopeModel hierarchy and use the level that matches the config type.
Example fix
// before moduleConfig.setScopeModel(applicationModel); // ApplicationModel, not ModuleModel // after moduleConfig.setScopeModel(applicationModel.getDefaultModule());
Defensive patterns
Strategy: type-guard
Validate before calling
// Validate scope before assignment
if (!(scopeModel instanceof ModuleModel)) {
throw new IllegalArgumentException(
"ModuleConfig requires a ModuleModel, got: " + scopeModel);
}
moduleConfig.setScopeModel(scopeModel); Type guard
static boolean isModuleModelScope(ScopeModel s) {
return s instanceof ModuleModel;
} Try / catch
try {
moduleConfig.setScopeModel(scopeModel);
} catch (IllegalArgumentException e) {
// resolve the correct scope level and retry
moduleConfig.setScopeModel(applicationModel.getDefaultModule());
} Prevention
- Remember the scope hierarchy: FrameworkModel -> ApplicationModel -> ModuleModel; ModuleConfig needs the leaf.
- Always pull the scope from the owning module, not the application/framework.
- Centralize scope-model assignment in a helper that asserts the correct type.
When it happens
Trigger: Calling setScopeModel (or refresh that triggers checkScopeModel) on a ModuleConfig with a ScopeModel that is not an instance of ModuleModel, e.g. passing an ApplicationModel or FrameworkModel.
Common situations: Manually wiring configs across scope boundaries (e.g. grabbing applicationModel and assigning it to a module config). Misunderstanding the Dubbo scope hierarchy (FrameworkModel -> ApplicationModel -> ModuleModel). Copy-pasting scope-model assignment code between config types with different requirements.
Related errors
- Invalid configurator rule, please specify at least one param
- service field in configuration is null.
- Illegal affinity rule!
- Illegal route rule!
- Illegal route rule!
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/35a213ec0b5ca97f.
Report an issue: GitHub.