apache/dubbo · error · IllegalStateException

Input type ${clazz} can't be interface!

Error message

Input type ${clazz} can't be interface!

What it means

Thrown by ExtensionLoader.addExtension(String name, Class<?> clazz) when the provided class is itself an interface. Dubbo SPI extensions must be instantiable concrete classes — interfaces cannot be instantiated. This guard runs after the assignability check, so the type is assignable (e.g., a sub-interface) but not a concrete implementation.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java:657

        return cachedDefaultName;
    }

    /**
     * Register new extension via API
     *
     * @param name  extension name
     * @param clazz extension class
     * @throws IllegalStateException when extension with the same name has already been registered.
     */
    public void addExtension(String name, Class<?> clazz) {
        checkDestroyed();
        getExtensionClasses(); // load classes

        if (!type.isAssignableFrom(clazz)) {
            throw new IllegalStateException("Input type " + clazz + " doesn't implement the Extension " + type);
        }
        if (clazz.isInterface()) {
            throw new IllegalStateException("Input type " + clazz + " can't be interface!");
        }

        if (!clazz.isAnnotationPresent(Adaptive.class)) {
            if (StringUtils.isBlank(name)) {
                throw new IllegalStateException("Extension name is blank (Extension " + type + ")!");
            }
            if (cachedClasses.get().containsKey(name)) {
                throw new IllegalStateException("Extension name " + name + " already exists (Extension " + type + ")!");
            }

            cachedNames.put(clazz, name);
            cachedClasses.get().put(name, clazz);
        } else {
            if (cachedAdaptiveClass != null) {
                throw new IllegalStateException("Adaptive Extension already exists (Extension " + type + ")!");
            }

            cachedAdaptiveClass = clazz;

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Pass a concrete class that implements the SPI interface, not an interface.
  2. If you intended to register an adaptive class, annotate it with @Adaptive and use the adaptive registration branch.
  3. Verify clazz.isInterface() returns false before calling addExtension.

Example fix

// before — registering an interface
loader.addExtension("subspi", MySubInterface.class);

// after — register a concrete class
class MySubImpl implements MySpi { ... }
loader.addExtension("subspi", MySubImpl.class);
Defensive patterns

Strategy: type-guard

Validate before calling

if (clazz.isInterface()) {
    throw new IllegalStateException(
        clazz + " is an interface — provide a concrete implementation class");
}
loader.addExtension(name, clazz);

Type guard

static boolean isConcreteClass(Class<?> clazz) {
    return clazz != null && !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers());
}

Prevention

When it happens

Trigger: Calling addExtension with an interface class object instead of a concrete implementation. For example, registering a sub-interface of the SPI type, or passing MySpi.class (the SPI interface itself) as an implementation.

Common situations: Developer passes the interface type (not annotated @Adaptive) rather than an implementation class. Confusion about the distinction between the extension point and the extension implementation during programmatic registration.

Related errors


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