{"record":{"id":"1123a177ec01929c","repo":"apache/dubbo","slug":"invocation-null","errorCode":null,"errorMessage":"invocation == null","messagePattern":"invocation == null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java","lineNumber":69,"sourceCode":"    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;\n\n    private final String defaultExtName;\n\n    public AdaptiveClassCodeGenerator(Class<?> type, String defaultExtName) {\n        this.type = type;\n        this.defaultExtName = defaultExtName;\n    }\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java#L51-L87","documentation":"This is a generated-code template (CODE_INVOCATION_ARGUMENT_NULL_CHECK) emitted into the adaptive class for @Adaptive methods that take an org.apache.dubbo.rpc.Invocation parameter. At runtime, the generated $Adaptive class throws IllegalArgumentException(\"invocation == null\") when the Invocation argument is null. The Invocation is needed to resolve method-scoped parameters via getMethodParameter.","triggerScenarios":"At runtime, calling a @Adaptive method that declares an Invocation-typed parameter (e.g. Invoker.invoke, Filter/Cluster SPI methods) and passing null for that argument. The generated check fires before methodName is extracted from the invocation.","commonSituations":"Calling an adaptive extension's invoke-related method with a null Invocation during unit tests or in custom framework integration code. Happens when a mock invoker chain fails to construct the Invocation object.","solutions":["Construct and pass a non-null Invocation (e.g. MockInvocation, or a real RpcInvocation) to the adaptive method.","Ensure the upstream caller (the Invoker chain or proxy) always builds the Invocation before delegating.","In tests, use Dubbo's test utilities or mock frameworks to create a valid Invocation."],"exampleFix":"// before\nadaptiveFilter.invoke(invoker, null); // throws\n\n// after\nInvocation inv = new RpcInvocation(\"methodName\", argTypes, args);\nadaptiveFilter.invoke(invoker, inv);","handlingStrategy":"validation","validationCode":"if (invocation == null) {\n    throw new IllegalArgumentException(\"Invocation must not be null\");\n}","typeGuard":"static boolean hasValidInvocation(Invocation inv) {\n    return inv != null && inv.getMethodName() != null;\n}","tryCatchPattern":"try {\n    adaptiveFilter.invoke(invoker, invocation);\n} catch (IllegalArgumentException e) {\n    if (\"invocation == null\".equals(e.getMessage())) {\n        invocation = new RpcInvocation(method, types, args);\n        adaptiveFilter.invoke(invoker, invocation);\n    } else throw e;\n}","preventionTips":["Always construct a non-null Invocation before calling invoke-style adaptive methods.","Use RpcInvocation or Dubbo test utilities for Invocation construction.","Validate the Invocation chain in invoker/filter wiring."],"tags":["spi","adaptive-extension","code-generation","null-check","invocation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}