{"record":{"id":"6b5e1ce5fb658bbc","repo":"alibaba/spring-ai-alibaba","slug":"fieldname-cannot-be-null-or-empty","errorCode":null,"errorMessage":"{fieldName} cannot be null or empty","messagePattern":"(.+?) cannot be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/FileSystemStore.java","lineNumber":271,"sourceCode":"\t * @return item path\n\t */\n\tprivate Path createItemPath(List<String> namespace, String key) {\n\t\tPath path = rootPath.toAbsolutePath().normalize();\n\t\tfor (String ns : namespace) {\n\t\t\tvalidatePathSegment(ns, \"namespace\");\n\t\t\tpath = path.resolve(ns);\n\t\t}\n\t\tvalidatePathSegment(key, \"key\");\n\t\tPath itemPath = path.resolve(key + \".json\").normalize();\n\t\tif (!itemPath.startsWith(rootPath.toAbsolutePath().normalize())) {\n\t\t\tthrow new IllegalArgumentException(\"resolved path escapes root directory\");\n\t\t}\n\t\treturn itemPath;\n\t}\n\n\tprivate void validatePathSegment(String segment, String fieldName) {\n\t\tif (segment == null || segment.trim().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(fieldName + \" cannot be null or empty\");\n\t\t}\n\t\tPath candidate = Paths.get(segment);\n\t\tif (candidate.isAbsolute() || candidate.getNameCount() != 1 || \"..\".equals(segment) || \".\".equals(segment)) {\n\t\t\tthrow new IllegalArgumentException(fieldName + \" contains unsafe path segment: \" + segment);\n\t\t}\n\t}\n\n\t/**\n\t * Ensure directory exists.\n\t * @param directory directory to create\n\t */\n\tprivate void ensureDirectoryExists(Path directory) throws IOException {\n\t\tif (!Files.exists(directory)) {\n\t\t\tFiles.createDirectories(directory);\n\t\t}\n\t}\n\n\t/**","sourceCodeStart":253,"sourceCodeEnd":289,"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/FileSystemStore.java#L253-L289","documentation":"FileSystemStore.validatePathSegment throws IllegalArgumentException('<field> cannot be null or empty') when a namespace element or key is null, empty, or whitespace-only. It is the first line of defense before path resolution in createItemPath.","triggerScenarios":"store.putItem(null, key, value), store.getItem(ns, \"\"), a namespace list containing an empty string element, or a key of only spaces — any call where a path segment is blank.","commonSituations":"Downstream code returning empty optional IDs; config placeholders left unresolved (empty property); splitting strings that yield empty tokens; forgotten default values in application.yml.","solutions":["Validate namespace and key are non-blank before calling any store method","Check that each element of the namespace list is non-empty","Fix the upstream source of the empty value (config, request param, split result)","Apply a default key when the caller's id is missing"],"exampleFix":"// before\nstore.putItem(namespace, itemId, value); // itemId may be \"\"\n// after\nif (itemId == null || itemId.isBlank()) {\n    throw new IllegalArgumentException(\"itemId is required\");\n}\nstore.putItem(namespace, itemId, value);","handlingStrategy":"validation","validationCode":"static void requireSegment(String v, String name) {\n    if (v == null || v.isBlank()) throw new IllegalArgumentException(name + \" required\");\n}\nrequireSegment(key, \"key\");\nnamespace == null || namespace.stream().forEach(n -> requireSegment(n, \"namespace\"));","typeGuard":"static boolean isUsableKey(String k) {\n    return k != null && !k.isBlank();\n}","tryCatchPattern":"try {\n    store.putItem(ns, key, value);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"rejected store argument: {}\", e.getMessage());\n}","preventionTips":["Validate ids at API boundaries before they reach the store","Provide defaults for optional ids","Watch for empty strings produced by String.split"],"tags":["validation","argument","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-17T15:17:12.973Z"}