apache/dubbo · critical · IllegalStateException

Failed to create adaptive class for interface ${type.getName

Error message

Failed to create adaptive class for interface ${type.getName()}: not found url parameter or url attribute in parameters of method ${method.getName()}

What it means

Thrown by AdaptiveClassCodeGenerator during class generation when a @Adaptive method has no URL-typed parameter AND no parameter with a getter method returning URL. The adaptive mechanism needs a URL to resolve the extension name; if it cannot find one directly or indirectly via getXxxUrl(), generation fails. The error names the interface and the offending method.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java:401

        Map<String, Integer> getterReturnUrl = new HashMap<>();
        // find URL getter method
        for (int i = 0; i < pts.length; ++i) {
            for (Method m : pts[i].getMethods()) {
                String name = m.getName();
                if ((name.startsWith("get") || name.length() > 3)
                        && Modifier.isPublic(m.getModifiers())
                        && !Modifier.isStatic(m.getModifiers())
                        && m.getParameterTypes().length == 0
                        && m.getReturnType() == URL.class) {
                    getterReturnUrl.put(name, i);
                }
            }
        }

        if (getterReturnUrl.size() <= 0) {
            // getter method not found, throw
            throw new IllegalStateException("Failed to create adaptive class for interface " + type.getName()
                    + ": not found url parameter or url attribute in parameters of method " + method.getName());
        }

        Integer index = getterReturnUrl.get("getUrl");
        if (index != null) {
            return generateGetUrlNullCheck(index, pts[index], "getUrl");
        } else {
            Map.Entry<String, Integer> entry =
                    getterReturnUrl.entrySet().iterator().next();
            return generateGetUrlNullCheck(entry.getValue(), pts[entry.getValue()], entry.getKey());
        }
    }

    /**
     * 1, test if argi is null
     * 2, test if argi.getXX() returns null
     * 3, assign url with argi.getXX()
     */

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Add a URL-typed parameter to the @Adaptive method, or
  2. Add a public no-arg getter returning org.apache.dubbo.common.URL to one of the parameter types (e.g. getUrl() on a context object).

Example fix

// before
@Adaptive
String doWork(String config);

// after
@Adaptive
String doWork(URL url, String config);
Defensive patterns

Strategy: validation

Validate before calling

boolean hasUrlParam = Arrays.stream(method.getParameterTypes())
    .anyMatch(p -> p == URL.class);
boolean hasUrlGetter = Arrays.stream(method.getParameterTypes())
    .flatMap(p -> Arrays.stream(p.getMethods()))
    .anyMatch(m -> m.getReturnType() == URL.class && m.getParameterCount() == 0);
if (!hasUrlParam && !hasUrlGetter) {
    // this @Adaptive method will fail code generation
}

Type guard

static boolean adaptiveMethodHasUrl(Method method) {
    Class<?>[] params = method.getParameterTypes();
    boolean directUrl = Arrays.asList(params).contains(URL.class);
    boolean indirectUrl = Arrays.stream(params)
        .flatMap(p -> Arrays.stream(p.getMethods()))
        .anyMatch(m -> m.getReturnType() == URL.class
            && Modifier.isPublic(m.getModifiers())
            && !Modifier.isStatic(m.getModifiers())
            && m.getParameterCount() == 0);
    return directUrl || indirectUrl;
}

Prevention

When it happens

Trigger: A @Adaptive method on an SPI interface whose parameter list contains neither a direct URL argument nor any argument exposing a URL via a public no-arg getter returning URL (e.g. getUrl()). Happens during getAdaptiveExtension() at startup.

Common situations: Designing a custom @Adaptive method with parameters that don't include URL or a URL-carrier object. Common when adapting an SPI from another framework whose parameter objects don't expose a Dubbo URL. Also happens if a wrapper object's getUrl() method was renamed or its return type changed away from URL.

Related errors


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