{"record":{"id":"ab6c2b0e3032776e","repo":"apache/dubbo","slug":"url-null","errorCode":null,"errorMessage":"url == null","messagePattern":"url == null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java","lineNumber":61,"sourceCode":"    private static final String CLASS_NAME_INVOCATION = \"org.apache.dubbo.rpc.Invocation\";\n\n    private static final String CODE_PACKAGE = \"package %s;\\n\";\n\n    private static final String CODE_IMPORTS = \"import %s;\\n\";\n\n    private static final String CODE_CLASS_DECLARATION = \"public class %s$Adaptive implements %s {\\n\";\n\n    private static final String CODE_METHOD_DECLARATION = \"public %s %s(%s) %s {\\n%s}\\n\";\n\n    private static final String CODE_METHOD_ARGUMENT = \"%s arg%d\";\n\n    private static final String CODE_METHOD_THROWS = \"throws %s\";\n\n    private static final String CODE_UNSUPPORTED =\n            \"throw new UnsupportedOperationException(\\\"The method %s of interface %s is not adaptive method!\\\");\\n\";\n\n    private static final String CODE_URL_NULL_CHECK =\n            \"if (arg%d == null) throw new IllegalArgumentException(\\\"url == null\\\");\\n%s url = arg%d;\\n\";\n\n    private static final String CODE_EXT_NAME_ASSIGNMENT = \"String extName = %s;\\n\";\n\n    private static final String CODE_EXT_NAME_NULL_CHECK = \"if(extName == null) \"\n            + \"throw new IllegalStateException(\\\"Failed to get extension (%s) name from url (\\\" + url.toString() + \\\") use keys(%s)\\\");\\n\";\n\n    private static final String CODE_INVOCATION_ARGUMENT_NULL_CHECK =\n            \"if (arg%d == null) throw new IllegalArgumentException(\\\"invocation == null\\\"); \"\n                    + \"String methodName = arg%d.getMethodName();\\n\";\n\n    private static final String CODE_SCOPE_MODEL_ASSIGNMENT =\n            \"ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), %s.class);\\n\";\n    private static final String CODE_EXTENSION_ASSIGNMENT =\n            \"%s extension = (%<s)scopeModel.getExtensionLoader(%s.class).getExtension(extName);\\n\";\n\n    private static final String CODE_EXTENSION_METHOD_INVOKE_ARGUMENT = \"arg%d\";\n\n    private final Class<?> type;","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java#L43-L79","documentation":"This is a generated-code template (CODE_URL_NULL_CHECK) emitted into the adaptive class for @Adaptive methods. At runtime, the generated $Adaptive class throws IllegalArgumentException(\"url == null\") when the URL-typed parameter passed to the method is null. Every adaptive method requires a non-null URL to resolve the extension name from its parameters.","triggerScenarios":"At runtime, calling a method on an adaptive extension instance and passing null for the URL parameter (the parameter whose type is org.apache.dubbo.common.URL). The generated null-check fires immediately before any extension resolution.","commonSituations":"User code or framework code calling an adaptive SPI method (e.g. Protocol.export, Invoker related methods) with a null URL because the URL was never constructed or was lost upstream. Happens during testing when mock setups omit URL construction.","solutions":["Ensure a non-null URL is constructed and passed to the adaptive method.","Use URL.valueOf(\"dubbo://127.0.0.1:20880/...\") or a Dubbo URL builder to create the URL before the call.","Trace upstream to find why the URL was null — typically a missing or failed URL construction in the caller."],"exampleFix":"// before\nadaptiveProtocol.export(null);\n\n// after\nURL url = URL.valueOf(\"dubbo://127.0.0.1:20880/org.example.Service\");\nadaptiveProtocol.export(url);","handlingStrategy":"validation","validationCode":"if (url == null) {\n    throw new IllegalArgumentException(\"URL must not be null before calling adaptive method\");\n}","typeGuard":"static boolean hasValidUrl(URL url) {\n    return url != null;\n}","tryCatchPattern":"try {\n    adaptiveProtocol.export(url);\n} catch (IllegalArgumentException e) {\n    if (\"url == null\".equals(e.getMessage())) {\n        url = URL.valueOf(defaultUrl);\n        adaptiveProtocol.export(url);\n    } else throw e;\n}","preventionTips":["Always construct and pass a non-null URL to adaptive methods.","Validate URL is non-null at the caller before delegating.","Use URL.valueOf() or URL builders to construct URLs."],"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"}