{"record":{"id":"ad03a0ca3687fcf7","repo":"spring-projects/spring-ai","slug":"request-must-not-be-null-ad03a0","errorCode":null,"errorMessage":"Request must not be null","messagePattern":"Request must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/SyncStatelessMcpCompleteMethodCallback.java","lineNumber":65,"sourceCode":"\t\tthis.validateMethod(this.method);\n\t}\n\n\t/**\n\t * Apply the callback to the given context and request.\n\t * <p>\n\t * This method builds the arguments for the method call, invokes the method, and\n\t * converts the result to a CompleteResult.\n\t * @param context The transport context, may be null if the method doesn't require it\n\t * @param request The complete request, must not be null\n\t * @return The complete result\n\t * @throws McpCompleteMethodException if there is an error invoking the complete\n\t * method\n\t * @throws IllegalArgumentException if the request is null\n\t */\n\t@Override\n\tpublic CompleteResult apply(McpTransportContext context, CompleteRequest request) {\n\t\tif (request == null) {\n\t\t\tthrow new IllegalArgumentException(\"Request must not be null\");\n\t\t}\n\n\t\ttry {\n\t\t\t// Build arguments for the method call\n\t\t\tObject[] args = this.buildArgs(this.method, context, request);\n\n\t\t\t// Invoke the method\n\t\t\tthis.method.setAccessible(true);\n\t\t\tObject result = this.method.invoke(this.bean, args);\n\n\t\t\t// Convert the result to a CompleteResult\n\t\t\treturn convertToCompleteResult(result);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new McpCompleteMethodException(\"Error invoking complete method: \" + this.method.getName(), e);\n\t\t}\n\t}\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/SyncStatelessMcpCompleteMethodCallback.java#L47-L83","documentation":"SyncStatelessMcpCompleteMethodCallback.apply throws this IllegalArgumentException when the CompleteRequest passed to the callback is null. The stateless completion callback requires a non-null request to extract the argument value being completed.","triggerScenarios":"Registering or invoking the callback programmatically and passing null as the CompleteRequest, or a transport/adapter layer that forwards a missing payload as null instead of a default request.","commonSituations":"Custom McpSyncServer wiring where the completion handler is called directly in unit tests or integration glue with a null request; framework-bridging code that does not guard against absent parameters.","solutions":["Always pass a constructed CompleteRequest (with its CompleteRequestArgument) to apply()","Add a null check in caller code before invoking the callback","If building requests manually in tests, use a representative instance like new CompleteRequest(new CompleteRequestArgument(\"val\"))"],"exampleFix":"// before\nCompleteResult r = callback.apply(context, null);\n// after\nif (request == null) { throw new IllegalArgumentException(\"request required\"); }\nCompleteResult r = callback.apply(context, request);","handlingStrategy":"validation","validationCode":"if (request == null)\n    throw new IllegalArgumentException(\"CompleteRequest is required before invoking the callback\");","typeGuard":"static boolean hasRequest(CompleteRequest r) { return r != null && r.argument() != null; }","tryCatchPattern":"try { return callback.apply(context, request); }\ncatch (IllegalArgumentException e) { log.error(\"null completion request: {}\", e.getMessage()); return new CompleteResult(new CompleteCompletion(List.of(), 0, false)); }","preventionTips":["Never call apply() manually with null; construct a CompleteRequest in tests","Ensure custom transports always map missing completion payloads to an empty CompleteRequestArgument rather than null","Add null assertions at transport boundaries"],"tags":["java","mcp","completion","null-check"],"backgroundTag":"null-argument","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}