{"record":{"id":"c5f0681990c6074f","repo":"alibaba/spring-ai-alibaba","slug":"namespacerequest-cannot-be-null","errorCode":null,"errorMessage":"namespaceRequest cannot be null","messagePattern":"namespaceRequest cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/BaseStore.java","lineNumber":110,"sourceCode":"\t}\n\n\t/**\n\t * Validates the searchItems parameters.\n\t * @param searchRequest search request\n\t */\n\tprotected void validateSearchItems(StoreSearchRequest searchRequest) {\n\t\tif (searchRequest == null) {\n\t\t\tthrow new IllegalArgumentException(\"searchRequest cannot be null\");\n\t\t}\n\t}\n\n\t/**\n\t * Validates the listNamespaces parameters.\n\t * @param namespaceRequest namespace request\n\t */\n\tprotected void validateListNamespaces(NamespaceListRequest namespaceRequest) {\n\t\tif (namespaceRequest == null) {\n\t\t\tthrow new IllegalArgumentException(\"namespaceRequest cannot be null\");\n\t\t}\n\t}\n\n\t/**\n\t * Create store key from namespace and key Uses safe encoding to avoid conflicts from\n\t * special characters.\n\t * @param namespace namespace\n\t * @param key key\n\t * @return store key\n\t */\n\tprotected String createStoreKey(List<String> namespace, String key) {\n\t\ttry {\n\t\t\tMap<String, Object> keyData = new HashMap<>();\n\t\t\tkeyData.put(\"namespace\", namespace);\n\t\t\tkeyData.put(\"key\", key);\n\t\t\treturn Base64.getEncoder().encodeToString(new ObjectMapper().writeValueAsBytes(keyData));\n\t\t}\n\t\tcatch (Exception e) {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/BaseStore.java#L92-L128","documentation":"BaseStore.validateListNamespaces requires a non-null NamespaceListRequest. The request object carries the prefix and paging options for enumerating namespaces; a null value is treated as an invalid argument rather than interpreted as 'list everything'.","triggerScenarios":"Calling store.listNamespaces(null), or passing an uninitialized/failed-to-build NamespaceListRequest.","commonSituations":"Optional request DTOs bound from HTTP bodies that are absent; builder chains short-circuited by earlier nulls; unit tests passing null expecting default behavior.","solutions":["Pass a NamespaceListRequest instance, using an empty/default one for unrestricted listings.","Default the parameter with Objects.requireNonNullElse(request, new NamespaceListRequest()).","Catch IllegalArgumentException where null is a valid client input and map it to a default request."],"exampleFix":"// before\nstore.listNamespaces(req); // req may be null\n// after\nNamespaceListRequest safeReq = req != null ? req : new NamespaceListRequest();\nstore.listNamespaces(safeReq);","handlingStrategy":"validation","validationCode":"if (request == null) {\n    request = new NamespaceListRequest();\n}\nstore.listNamespaces(request);","typeGuard":"NamespaceListRequest orDefault(NamespaceListRequest r) { return r != null ? r : new NamespaceListRequest(); }","tryCatchPattern":"try {\n    store.listNamespaces(request);\n} catch (IllegalArgumentException e) {\n    store.listNamespaces(new NamespaceListRequest());\n}","preventionTips":["Default absent request bodies to an empty request object in controllers.","Document that null does not mean 'list all' for this API.","Add bean-validation (@NotNull) on request parameters at the entry point."],"tags":["java","validation","null-argument","store"],"backgroundTag":"null-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}