apache/dubbo · error · IllegalArgumentException

%s argument == null

Error message

%s argument == null

What it means

This is a generated-code template emitted by generateGetUrlNullCheck() into the adaptive class for @Adaptive methods that obtain their URL indirectly (via a getter on a non-URL parameter). At runtime, the generated class throws IllegalArgumentException when that carrier argument itself is null. The message names the argument's fully-qualified class name.

Source

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

        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()
     */
    private String generateGetUrlNullCheck(int index, Class<?> type, String method) {
        // Null point check
        StringBuilder code = new StringBuilder();
        code.append(String.format(
                "if (arg%d == null) throw new IllegalArgumentException(\"%s argument == null\");\n",
                index, type.getName()));
        code.append(String.format(
                "if (arg%d.%s() == null) throw new IllegalArgumentException(\"%s argument %s() == null\");\n",
                index, method, type.getName(), method));

        code.append(String.format("%s url = arg%d.%s();\n", URL.class.getName(), index, method));
        return code.toString();
    }
}

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Ensure the carrier argument (the object whose getter returns URL) is non-null before calling the adaptive method.
  2. Trace upstream to find why the carrier object was null.
  3. If the object is optional, restructure to pass a URL directly as a parameter instead.

Example fix

// before
adaptiveSpi.doWork(null); // carrier arg is null

// after
InvocationContext ctx = buildContext();
adaptiveSpi.doWork(ctx); // ctx.getUrl() provides URL
Defensive patterns

Strategy: validation

Validate before calling

if (carrierArg == null) {
    throw new IllegalArgumentException("Carrier argument must not be null");
}

Type guard

static boolean hasNonNullCarrier(Object carrier) {
    return carrier != null;
}

Try / catch

try {
    adaptiveMethod(carrier);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("argument == null")) {
        carrier = buildCarrierWithUrl();
        adaptiveMethod(carrier);
    } else throw e;
}

Prevention

When it happens

Trigger: At runtime, calling a @Adaptive method where the URL is obtained indirectly via argX.getUrl() but argX is null. The generated check 'if (argN == null) throw new IllegalArgumentException("<type> argument == null")' fires first, before the getter call.

Common situations: Calling an adaptive SPI method whose URL comes from a context/invocation object, and that object was never set or was lost. For example a method like doWork(InvocationContext ctx) where ctx.getUrl() provides the URL, but ctx is null.

Related errors


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