apache/dubbo · error · IllegalArgumentException

Invalid scope model, expect to be a ApplicationModel but got

Error message

Invalid scope model, expect to be a ApplicationModel but got: <scopeModel>

What it means

Thrown by AbstractConfig.checkScopeModel during setScopeModel: the argument is not an instanceof ApplicationModel. The base AbstractConfig requires an ApplicationModel-level scope. Subclasses like Module-scoped configs override checkScopeModel to allow ModuleModel, but the default rejects anything else with IllegalArgumentException.

Source

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

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

    public final void setScopeModel(ScopeModel scopeModel) {
        if (scopeModel != null && this.scopeModel != scopeModel) {
            checkScopeModel(scopeModel);
            ScopeModel oldScopeModel = this.scopeModel;
            this.scopeModel = scopeModel;
            // reinitialize spi extension and change referenced config's scope model
            this.postProcessAfterScopeModelChanged(oldScopeModel, this.scopeModel);
        }
    }

    protected void checkScopeModel(ScopeModel scopeModel) {
        if (!(scopeModel instanceof ApplicationModel)) {
            throw new IllegalArgumentException(
                    "Invalid scope model, expect to be a ApplicationModel but got: " + scopeModel);
        }
    }

    /**
     * Subclass should override this method to initialize its SPI extensions and change referenced config's scope model.
     * <p>
     * For example:
     * <pre>
     * protected void postProcessAfterScopeModelChanged() {
     *   super.postProcessAfterScopeModelChanged();
     *   // re-initialize spi extension
     *   this.protocol = this.getExtensionLoader(Protocol.class).getAdaptiveExtension();
     *   // change referenced config's scope model
     *   if (this.providerConfig != null && this.providerConfig.getScopeModel() != scopeModel) {
     *     this.providerConfig.setScopeModel(scopeModel);
     *   }
     * }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Pass an ApplicationModel instance to setScopeModel; derive one from a FrameworkModel via defaultApplicationModel().
  2. If the config should be module-scoped, override checkScopeModel in the subclass to accept ModuleModel.
  3. Do not setScopeModel with FrameworkModel or custom subtypes on base AbstractConfig.
  4. After a Dubbo upgrade, re-check the ScopeModel type expected by your config wiring.

Example fix

// before
config.setScopeModel(moduleModel); // base AbstractConfig rejects this
// after
// use the application model (moduleModel.getApplicationModel())
config.setScopeModel(moduleModel.getApplicationModel());
Defensive patterns

Strategy: type-guard

Validate before calling

void setAppScopeModel(AbstractConfig cfg, ScopeModel m) {
    if (!(m instanceof ApplicationModel)) {
        throw new IllegalArgumentException("ApplicationModel required, got " + m);
    }
    cfg.setScopeModel(m);
}

Type guard

boolean isApplicationModel(ScopeModel m) { return m instanceof ApplicationModel; }

Try / catch

try {
    config.setScopeModel(candidate);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Invalid scope model")) { /* pass ApplicationModel instead */ }
    throw e;
}

Prevention

When it happens

Trigger: config.setScopeModel(someScopeModel) is called where someScopeModel is a FrameworkModel, a ModuleModel (on a config whose checkScopeModel isn't overridden to allow it), or a custom ScopeModel. Happens during explicit model assignment or when Dubbo internally propagates a model.

Common situations: Mixing a FrameworkModel where an ApplicationModel is expected (e.g. multi-ApplicationSet setups). Assigning a ModuleModel to a config type that only accepts ApplicationModel. Custom config subclass forgetting to override checkScopeModel when module-scoped.

Related errors


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