{"record":{"id":"5157403bdb086238","repo":"spring-projects/spring-ai","slug":"failed-to-create-new-file","errorCode":null,"errorMessage":"Failed to create new file: ","messagePattern":"Failed to create new file: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java","lineNumber":188,"sourceCode":"\t/**\n\t * Serialize the vector store content into a file in JSON format.\n\t * @param file the file to save the vector store content\n\t */\n\tpublic void save(File file) {\n\t\tString json = getVectorDbAsJson();\n\t\ttry {\n\t\t\tif (!file.exists()) {\n\t\t\t\tif (logger.isInfoEnabled()) {\n\t\t\t\t\tlogger.info(\"Creating new vector store file: \" + file);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tFiles.createFile(file.toPath());\n\t\t\t\t}\n\t\t\t\tcatch (FileAlreadyExistsException e) {\n\t\t\t\t\tthrow new RuntimeException(\"File already exists: \" + file, e);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(\"Failed to create new file: \" + file + \". Reason: \" + e.getMessage(), e);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (logger.isInfoEnabled()) {\n\t\t\t\tlogger.info(\"Overwriting existing vector store file: \" + file);\n\t\t\t}\n\t\t\ttry (OutputStream stream = new FileOutputStream(file);\n\t\t\t\t\tWriter writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) {\n\t\t\t\twriter.write(json);\n\t\t\t\twriter.flush();\n\t\t\t}\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tlogger.error(\"IOException occurred while saving vector store file.\", ex);\n\t\t\tthrow new RuntimeException(ex);\n\t\t}\n\t\tcatch (SecurityException ex) {\n\t\t\tlogger.error(\"SecurityException occurred while saving vector store file.\", ex);\n\t\t\tthrow new RuntimeException(ex);","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java#L170-L206","documentation":"SimpleVectorStore.save() wraps a generic IOException from Files.createFile() in a RuntimeException with the message 'Failed to create new file: <file>'. It means the JVM could not create the persistence file for reasons other than it already existing (permissions, missing parent directory, disk full).","triggerScenarios":"Calling persist() where the target directory does not exist or is not writable, the disk is full, or an I/O error occurs while creating the file.","commonSituations":"Misconfigured data directory path; running in a read-only container filesystem; insufficient permissions for the user the app runs as; missing parent directories.","solutions":["Ensure the parent directory exists and is writable by the process user (Files.createDirectories on startup).","Fix filesystem permissions or run the process with adequate rights.","Check free disk space and mount state; in containers verify the volume is not read-only."],"exampleFix":"// before\nvectorStore.save(new File(\"/var/lib/app/store.json\"));\n\n// after\nFile file = new File(\"/var/lib/app/store.json\");\nFiles.createDirectories(file.getParentFile().toPath());\nvectorStore.save(file);","handlingStrategy":"validation","validationCode":"File file = new File(path);\nFiles.createDirectories(file.getParentFile().toPath());\nif (!Files.isWritable(file.getParentFile().toPath())) {\n    throw new IllegalStateException(\"Data dir not writable: \" + file.getParent());\n}\nvectorStore.save(file);","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.save(file);\n} catch (RuntimeException e) {\n    logger.error(\"Could not create vector store file {}: {}\", file, e.getMessage());\n}","preventionTips":["Create and verify parent directories at application startup.","Check disk space and read-only mounts in containers.","Run the service with a user that owns the data directory."],"tags":["file-io","ioexception","vector-store"],"backgroundTag":"file-write-failed","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"}