apache/dubbo · error · IllegalArgumentException

Unable to get ModuleModel from ${scopeModel}

Error message

Unable to get ModuleModel from ${scopeModel}

What it means

ScopeModelUtil.getModuleModel() narrows a ScopeModel to a ModuleModel. If the argument is non-null but is neither a ModuleModel nor null, it cannot be converted and is rejected. (Note: FrameworkModel and ApplicationModel are not auto-narrowed here — only an explicit ModuleModel or null is accepted.) The message echoes the offending model's toString for diagnosis.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelUtil.java:55

            case FRAMEWORK:
                return FrameworkModel.defaultModel();
            case APPLICATION:
                return ApplicationModel.defaultModel();
            case MODULE:
                return ApplicationModel.defaultModel().getDefaultModule();
            default:
                throw new IllegalStateException("Unable to get default scope model for type: " + type.getName());
        }
    }

    public static ModuleModel getModuleModel(ScopeModel scopeModel) {
        if (scopeModel == null) {
            return ApplicationModel.defaultModel().getDefaultModule();
        }
        if (scopeModel instanceof ModuleModel) {
            return (ModuleModel) scopeModel;
        } else {
            throw new IllegalArgumentException("Unable to get ModuleModel from " + scopeModel);
        }
    }

    public static ApplicationModel getApplicationModel(ScopeModel scopeModel) {
        return getOrDefaultApplicationModel(scopeModel);
    }

    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;
        }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Pass a ModuleModel: derive it via `applicationModel.getDefaultModule()` or `moduleModel` from the correct scope before calling getModuleModel.
  2. If you only have an ApplicationModel, use `ScopeModelUtil.getApplicationModel(appModel).getDefaultModule()` to reach the module.
  3. Null is accepted (it resolves to the default application's default module), so prefer passing null over a wrong-typed model when you genuinely want the default.

Example fix

// before (throws: appModel is not a ModuleModel)
ModuleModel m = ScopeModelUtil.getModuleModel(applicationModel);

// after
ModuleModel m = ScopeModelUtil.getApplicationModel(applicationModel).getDefaultModule();
Defensive patterns

Strategy: type-guard

Validate before calling

ModuleModel module;
if (scopeModel == null) {
    module = ApplicationModel.defaultModel().getDefaultModule();
} else if (scopeModel instanceof ModuleModel) {
    module = (ModuleModel) scopeModel;
} else if (scopeModel instanceof ApplicationModel) {
    module = ((ApplicationModel) scopeModel).getDefaultModule();
} else {
    throw new IllegalArgumentException("Cannot resolve ModuleModel from " + scopeModel);
}

Type guard

static boolean isModuleOrResolvable(ScopeModel s) {
    return s == null || s instanceof ModuleModel || s instanceof ApplicationModel;
}

Prevention

When it happens

Trigger: Calling ScopeModelUtil.getModuleModel(applicationModel) or getModuleModel(frameworkModel) — passing an ApplicationModel or FrameworkModel where a ModuleModel is required. Often reached when a helper that holds a generic ScopeModel forwards it to getModuleModel without first descending to the module level.

Common situations: Integrations that capture a ScopeModel from getOrDefault() and later assume it is module-scoped. Config holders wired with an ApplicationModel where a ModuleModel was expected. Code that worked when the default scope happened to be a module but breaks when an application/framework model is supplied.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/856d5ebf3f790fac. Report an issue: GitHub.