{"record":{"id":"eb5a281b5ab7d38b","repo":"apache/dubbo","slug":"s-argument-null","errorCode":null,"errorMessage":"%s argument == null","messagePattern":"(.+?) argument == null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java","lineNumber":424,"sourceCode":"        if (index != null) {\n            return generateGetUrlNullCheck(index, pts[index], \"getUrl\");\n        } else {\n            Map.Entry<String, Integer> entry =\n                    getterReturnUrl.entrySet().iterator().next();\n            return generateGetUrlNullCheck(entry.getValue(), pts[entry.getValue()], entry.getKey());\n        }\n    }\n\n    /**\n     * 1, test if argi is null\n     * 2, test if argi.getXX() returns null\n     * 3, assign url with argi.getXX()\n     */\n    private String generateGetUrlNullCheck(int index, Class<?> type, String method) {\n        // Null point check\n        StringBuilder code = new StringBuilder();\n        code.append(String.format(\n                \"if (arg%d == null) throw new IllegalArgumentException(\\\"%s argument == null\\\");\\n\",\n                index, type.getName()));\n        code.append(String.format(\n                \"if (arg%d.%s() == null) throw new IllegalArgumentException(\\\"%s argument %s() == null\\\");\\n\",\n                index, method, type.getName(), method));\n\n        code.append(String.format(\"%s url = arg%d.%s();\\n\", URL.class.getName(), index, method));\n        return code.toString();\n    }\n}\n","sourceCodeStart":406,"sourceCodeEnd":434,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java#L406-L434","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the carrier argument (the object whose getter returns URL) is non-null before calling the adaptive method.","Trace upstream to find why the carrier object was null.","If the object is optional, restructure to pass a URL directly as a parameter instead."],"exampleFix":"// before\nadaptiveSpi.doWork(null); // carrier arg is null\n\n// after\nInvocationContext ctx = buildContext();\nadaptiveSpi.doWork(ctx); // ctx.getUrl() provides URL","handlingStrategy":"validation","validationCode":"if (carrierArg == null) {\n    throw new IllegalArgumentException(\"Carrier argument must not be null\");\n}","typeGuard":"static boolean hasNonNullCarrier(Object carrier) {\n    return carrier != null;\n}","tryCatchPattern":"try {\n    adaptiveMethod(carrier);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"argument == null\")) {\n        carrier = buildCarrierWithUrl();\n        adaptiveMethod(carrier);\n    } else throw e;\n}","preventionTips":["Ensure the carrier object (whose getter returns URL) is non-null.","Validate carrier arguments before calling adaptive methods.","Trace null carriers to their construction site."],"tags":["spi","adaptive-extension","code-generation","null-check","url"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}