apache/dubbo · error · IllegalStateException

scope model is invalid: <scopeModel>

Error message

scope model is invalid: <scopeModel>

What it means

Thrown by AbstractConfig.getApplicationModel(): the scopeModel is non-null and set, but it is neither an ApplicationModel nor a ModuleModel. After auto-defaulting (which would assign ApplicationModel.defaultModel()), reaching this branch means an exotic/invalid ScopeModel subtype was injected.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java:429

            // For compatibility, key like "registry-type" will have a duplicate key "registry.type"
            if (Arrays.binarySearch(Constants.DOT_COMPATIBLE_KEYS, key) >= 0) {
                result.put(pre + key.replace('-', '.'), value);
            }
        }
        return result;
    }

    @Transient
    public ApplicationModel getApplicationModel() {
        if (scopeModel == null) {
            setScopeModel(getDefaultModel());
        }
        if (scopeModel instanceof ApplicationModel) {
            return (ApplicationModel) scopeModel;
        } else if (scopeModel instanceof ModuleModel) {
            return ((ModuleModel) scopeModel).getApplicationModel();
        } else {
            throw new IllegalStateException("scope model is invalid: " + scopeModel);
        }
    }

    @Transient
    public ScopeModel getScopeModel() {
        if (scopeModel == null) {
            setScopeModel(getDefaultModel());
        }
        return scopeModel;
    }

    @Transient
    protected ScopeModel getDefaultModel() {
        return ApplicationModel.defaultModel();
    }

    public final void setScopeModel(ScopeModel scopeModel) {
        if (scopeModel != null && this.scopeModel != scopeModel) {

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Ensure you pass an ApplicationModel (or ModuleModel) to setScopeModel, not a FrameworkModel.
  2. If you only have a FrameworkModel, obtain its application model: frameworkModel.defaultApplicationModel() / getDefaultModule().
  3. Avoid calling setScopeModel with null/custom subtypes; let Dubbo default it.
  4. On upgrade, verify model wiring matches the Dubbo version's ScopeModel hierarchy.

Example fix

// before
config.setScopeModel(frameworkModel); // wrong type
// after
config.setScopeModel(frameworkModel.defaultApplicationModel());
Defensive patterns

Strategy: type-guard

Validate before calling

void safeSetScopeModel(AbstractConfig cfg, ScopeModel m) {
    if (m instanceof ApplicationModel || m instanceof ModuleModel) {
        cfg.setScopeModel(m);
    } else {
        throw new IllegalArgumentException("expected ApplicationModel/ModuleModel, got " + m);
    }
}

Type guard

boolean isAcceptableScopeModel(ScopeModel m) {
    return m instanceof ApplicationModel || m instanceof ModuleModel;
}

Try / catch

try {
    return config.getApplicationModel();
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("scope model is invalid")) { /* reset to default model */ }
    throw e;
}

Prevention

When it happens

Trigger: setScopeModel was called with a ScopeModel that is not ApplicationModel or ModuleModel (e.g. a FrameworkModel or a custom ScopeModel subclass), and getApplicationModel() is later called. This is rare; the default path assigns an ApplicationModel.

Common situations: Programmatically calling config.setScopeModel(frameworkModel) by mistake. A custom ScopeModel subclass was used. Internal Dubbo model wiring bug after a partial migration between Dubbo versions.

Related errors


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