{"record":{"id":"95e7a151fec8f0ba","repo":"spring-projects/spring-ai","slug":"updated-resources-list-must-not-be-null","errorCode":null,"errorMessage":"Updated resources list must not be null","messagePattern":"Updated resources list 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/changed/resource/SyncMcpResourceListChangedMethodCallback.java","lineNumber":56,"sourceCode":"\t\timplements Consumer<List<McpSchema.Resource>> {\n\n\tprivate SyncMcpResourceListChangedMethodCallback(Builder builder) {\n\t\tsuper(builder.method, builder.bean);\n\t}\n\n\t/**\n\t * Accept the resource list change notification and process it.\n\t * <p>\n\t * This method builds the arguments for the method call and invokes the method.\n\t * @param updatedResources The updated list of resources, must not be null\n\t * @throws McpResourceListChangedConsumerMethodException if there is an error invoking\n\t * the resource list changed consumer method\n\t * @throws IllegalArgumentException if the updatedResources is null\n\t */\n\t@Override\n\tpublic void accept(List<McpSchema.Resource> updatedResources) {\n\t\tif (updatedResources == null) {\n\t\t\tthrow new IllegalArgumentException(\"Updated resources list 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, null, updatedResources);\n\n\t\t\t// Invoke the method\n\t\t\tthis.method.setAccessible(true);\n\t\t\tthis.method.invoke(this.bean, args);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new McpResourceListChangedConsumerMethodException(\n\t\t\t\t\t\"Error invoking resource list changed consumer method: \" + this.method.getName(), e);\n\t\t}\n\t}\n\n\t/**\n\t * Validates that the method return type is compatible with the resource list changed","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/changed/resource/SyncMcpResourceListChangedMethodCallback.java#L38-L74","documentation":"SyncMcpResourceListChangedMethodCallback.accept(List<McpSchema.Resource>) rejects a null updatedResources list with IllegalArgumentException before invoking the consumer method. The library treats null as an invalid notification payload rather than an empty change set.","triggerScenarios":"Calling accept(null) directly, or a server/notification path delivering a resource-list-changed event with a null resources list into a sync callback.","commonSituations":"Custom or test harness code simulating resource change notifications and passing null instead of an empty list.","solutions":["Pass an empty List (List.of() / Collections.emptyList()) instead of null when no resources exist.","Null-check the notification payload before invoking accept().","If this comes from a custom transport, normalize null lists to empty lists at the transport layer."],"exampleFix":"// before\ncallback.accept(null);\n// after\ncallback.accept(updatedResources == null ? List.of() : updatedResources);","handlingStrategy":"validation","validationCode":"if (updatedResources == null) { updatedResources = List.of(); }","typeGuard":"static List<McpSchema.Resource> orEmpty(List<McpSchema.Resource> l) {\n    return l == null ? List.of() : l;\n}","tryCatchPattern":"try {\n    callback.accept(updatedResources);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Updated resources list must not be null\")) {\n        log.warn(\"Received null resources payload; treating as empty\");\n    }\n    throw e;\n}","preventionTips":["Normalize null lists to empty lists at the transport/notification layer.","Never pass null where the API documents List<McpSchema.Resource>."],"tags":["java","mcp","null","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}