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

  1. Pass one of the built-in subtypes (FrameworkModel/ApplicationModel/ModuleModel) or null to get the default framework.
  2. If you subclassed ScopeModel, cast/resolve to the nearest real subtype before calling getFrameworkModel.
  3. 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

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


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