apache/dubbo · warning · IllegalArgumentException

Current ServiceModel is not a ConsumerModel

Error message

Current ServiceModel is not a ConsumerModel

What it means

ServiceModel.getReferenceConfig() is a deprecated accessor that returns the stored config only if it is a ReferenceConfigBase (consumer side). If the ServiceModel was built from a ServiceConfigBase (provider side) or holds some other config type, the cast is impossible and Dubbo throws rather than returning a wrong object. The method is marked @Deprecated because ServiceModel is being decoupled from AbstractInterfaceConfig.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java:97

    @Deprecated
    public void setConfig(AbstractInterfaceConfig config) {
        this.config = config;
    }

    /**
     * ServiceModel should be decoupled from AbstractInterfaceConfig and removed in a future version
     * @return
     */
    @Deprecated
    public ReferenceConfigBase<?> getReferenceConfig() {
        if (config == null) {
            return null;
        }
        if (config instanceof ReferenceConfigBase) {
            return (ReferenceConfigBase<?>) config;
        } else {
            throw new IllegalArgumentException("Current ServiceModel is not a ConsumerModel");
        }
    }

    /**
     * ServiceModel should be decoupled from AbstractInterfaceConfig and removed in a future version
     * @return
     */
    @Deprecated
    public ServiceConfigBase<?> getServiceConfig() {
        if (config == null) {
            return null;
        }
        if (config instanceof ServiceConfigBase) {
            return (ServiceConfigBase<?>) config;
        } else {
            throw new IllegalArgumentException("Current ServiceModel is not a ProviderModel");
        }
    }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Check the config type before calling: `if (serviceModel.getConfig() instanceof ReferenceConfigBase) { ... }`.
  2. Prefer the non-deprecated APIs that do not assume config subtype; track consumer/provider identity via your own reference rather than via ServiceModel.config.
  3. If you hold a ConsumerModel (a ServiceModel subtype), call getReferenceConfig() only on consumer models — narrow the type first.

Example fix

// before (throws on a provider ServiceModel)
ReferenceConfigBase<?> ref = serviceModel.getReferenceConfig();

// after
if (serviceModel.getConfig() instanceof ReferenceConfigBase) {
    ReferenceConfigBase<?> ref = (ReferenceConfigBase<?>) serviceModel.getConfig();
    // use ref
} else {
    // this is a provider or non-reference model; handle accordingly
}
Defensive patterns

Strategy: type-guard

Validate before calling

ReferenceConfigBase<?> ref = null;
AbstractInterfaceConfig cfg = serviceModel.getConfig();
if (cfg instanceof ReferenceConfigBase) {
    ref = (ReferenceConfigBase<?>) cfg;
} // else: not a consumer model — do not call getReferenceConfig()

Type guard

static boolean isConsumerModel(ServiceModel sm) {
    return sm != null && sm.getConfig() instanceof ReferenceConfigBase;
}

Prevention

When it happens

Trigger: Calling serviceModel.getReferenceConfig() on a ServiceModel whose config is a ServiceConfigBase (i.e. a provider model) or a non-reference config. Common when generic code holds a ServiceModel and assumes it is consumer-side without checking.

Common situations: Tooling/introspection that iterates ServiceModels and calls both getReferenceConfig() and getServiceConfig() blindly. Code migrated from older Dubbo where ServiceModel was untyped. Calling getReferenceConfig() on a model obtained from a provider-side registry path.

Related errors


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