{"record":{"id":"293b8daeb97d1569","repo":"apache/dubbo","slug":"s-argument-s-null","errorCode":null,"errorMessage":"%s argument %s() == 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":427,"sourceCode":"            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":409,"sourceCodeEnd":434,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java#L409-L434","documentation":"This is a generated-code template emitted by generateGetUrlNullCheck() into the adaptive class. At runtime, the generated class throws IllegalArgumentException when the carrier argument is non-null but its URL getter (e.g. getUrl()) returns null. The message names both the argument's class and the getter method name.","triggerScenarios":"At runtime, calling a @Adaptive method where the URL is obtained via argX.getUrl(), the argument argX is non-null, but argX.getUrl() returns null. The generated second null-check fires: 'if (argN.getXxx() == null) throw new IllegalArgumentException(\"<type> argument <getter>() == null\")'.","commonSituations":"The carrier object exists but its URL field was never initialized — e.g. an InvocationContext or Invoker whose URL was not set during construction. Happens when objects are created by factories that don't always populate URL, or after deserialization that lost the URL.","solutions":["Ensure the carrier object's URL field is initialized before it reaches the adaptive method (e.g. pass a non-null URL to the carrier's constructor).","Trace the carrier object's construction to confirm the URL is set.","If the URL may legitimately be absent, restructure the call to pass a URL directly."],"exampleFix":"// before\nContext ctx = new Context(); // getUrl() returns null\nadaptiveSpi.doWork(ctx);\n\n// after\nURL url = URL.valueOf(\"dubbo://127.0.0.1:20880/Service\");\nContext ctx = new Context(url); // getUrl() now non-null\nadaptiveSpi.doWork(ctx);","handlingStrategy":"validation","validationCode":"URL url = carrier.getUrl();\nif (url == null) {\n    throw new IllegalArgumentException(\"Carrier's URL getter returned null\");\n}","typeGuard":"static boolean carrierHasUrl(Object carrier) throws Exception {\n    if (carrier == null) return false;\n    for (Method m : carrier.getClass().getMethods()) {\n        if (m.getReturnType() == URL.class && m.getParameterCount() == 0) {\n            return m.invoke(carrier) != null;\n        }\n    }\n    return false;\n}","tryCatchPattern":"try {\n    adaptiveMethod(carrier);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"() == null\")) {\n        // re-initialize carrier with URL and retry\n    } else throw e;\n}","preventionTips":["Initialize the URL field on carrier objects before they reach adaptive methods.","Ensure constructors or factories for carrier objects always set URL.","Check for null URLs after deserialization of carrier objects."],"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"}