{"record":{"id":"0572d5f6f5bfa21a","repo":"alibaba/spring-ai-alibaba","slug":"key-cannot-be-empty","errorCode":null,"errorMessage":"key cannot be empty","messagePattern":"key cannot be empty","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":73,"sourceCode":"\t\tif (item.getKey() == null || item.getKey().trim().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"key cannot be null or empty\");\n\t\t}\n\t}\n\n\t/**\n\t * Validates the getItem parameters.\n\t * @param namespace namespace\n\t * @param key key\n\t */\n\tprotected void validateGetItem(List<String> namespace, String key) {\n\t\tif (namespace == null) {\n\t\t\tthrow new IllegalArgumentException(\"namespace cannot be null\");\n\t\t}\n\t\tif (key == null) {\n\t\t\tthrow new IllegalArgumentException(\"key cannot be null\");\n\t\t}\n\t\tif (key.trim().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"key cannot be empty\");\n\t\t}\n\t}\n\n\t/**\n\t * Validates the deleteItem parameters.\n\t * @param namespace namespace\n\t * @param key key\n\t */\n\tprotected void validateDeleteItem(List<String> namespace, String key) {\n\t\tif (namespace == null) {\n\t\t\tthrow new IllegalArgumentException(\"namespace cannot be null\");\n\t\t}\n\t\tif (key == null) {\n\t\t\tthrow new IllegalArgumentException(\"key cannot be null\");\n\t\t}\n\t\tif (key.trim().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"key cannot be empty\");\n\t\t}","sourceCodeStart":55,"sourceCodeEnd":91,"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#L55-L91","documentation":"BaseStore.validateGetItem rejects a key that is null or blank (key.trim().isEmpty()) when reading a store item. An empty key cannot identify an item, so the library treats it as an invalid argument. Whitespace-only keys are also rejected.","triggerScenarios":"Calling store.getItem(namespace, \"\") or getItem(namespace, \"   \") with a blank/whitespace-only key string.","commonSituations":"Unset or defaulted string fields (e.g. String key = \"\"), template placeholders never substituted, empty form/query parameters forwarded directly to the store API.","solutions":["Validate the key is non-blank before calling getItem and fail fast with a clear message.","Trim user-supplied keys and reject empties at your API boundary.","Provide a default key or return a not-found response instead of calling getItem with a blank key."],"exampleFix":"// before\nstore.getItem(List.of(\"users\"), key.trim());\n// after\nString trimmed = key == null ? \"\" : key.trim();\nif (trimmed.isEmpty()) {\n    return Optional.empty();\n}\nstore.getItem(List.of(\"users\"), trimmed);","handlingStrategy":"validation","validationCode":"if (key == null || key.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"store item key must be non-blank\");\n}\nstore.getItem(namespace, key.trim());","typeGuard":"boolean isNotBlank(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try {\n    store.getItem(namespace, key);\n} catch (IllegalArgumentException e) {\n    return Optional.empty(); // treat blank key as not-found\n}","preventionTips":["Trim user-supplied keys before storing or looking them up.","Reject empty inputs in forms/config with clear validation messages.","Avoid \"\" as a default field value; prefer null plus explicit checks."],"tags":["java","validation","empty-string","store"],"backgroundTag":"empty-required-field","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"}