{"record":{"id":"6f564d0124164ca0","repo":"alibaba/nacos","slug":"file-not-exist","errorCode":null,"errorMessage":"file not exist","messagePattern":"file not exist","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/utils/ConcurrentDiskUtil.java","lineNumber":123,"sourceCode":"     * @throws IOException IOException\n     */\n    public static Boolean writeFileContent(File file, String content, String charsetName)\n        throws IOException {\n        \n        if (!file.exists() && !file.createNewFile()) {\n            return false;\n        }\n        try (RandomAccessFile raf = new RandomAccessFile(file, READ_WRITE);\n            FileChannel channel = raf.getChannel();\n            FileLock lock = tryLock(file, channel, false)) {\n            byte[] contentBytes = content.getBytes(charsetName);\n            ByteBuffer sendBuffer = ByteBuffer.wrap(contentBytes);\n            while (sendBuffer.hasRemaining()) {\n                channel.write(sendBuffer);\n            }\n            channel.truncate(contentBytes.length);\n        } catch (FileNotFoundException e) {\n            throw new IOException(\"file not exist\");\n        }\n        return true;\n    }\n    \n    /**\n     * transfer ByteBuffer to String.\n     *\n     * @param buffer      buffer\n     * @param charsetName charsetName\n     * @return String\n     * @throws IOException IOException\n     */\n    public static String byteBufferToString(ByteBuffer buffer, String charsetName)\n        throws IOException {\n        Charset charset = Charset.forName(charsetName);\n        CharsetDecoder decoder = charset.newDecoder();\n        CharBuffer charBuffer = decoder.decode(buffer.asReadOnlyBuffer());\n        return charBuffer.toString();","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/utils/ConcurrentDiskUtil.java#L105-L141","documentation":"Thrown by ConcurrentDiskUtil.writeFileContent when opening the file with RandomAccessFile raises FileNotFoundException, which is re-thrown as IOException with this message. The file was checked/created just above, so this indicates it was deleted between the existence check and the open, or it is a directory, or permissions prevent access.","triggerScenarios":"Between createNewFile() and new RandomAccessFile(file, 'rw'), the file is deleted by another process; the path points to a directory; or the JVM lacks read/write permission on the file after creation.","commonSituations":"Concurrent processes cleaning up temp/config directories; the file path actually resolves to a directory; filesystem permissions changed; the disk is full or the filesystem is read-only causing createNewFile to silently fail in a race.","solutions":["Verify the file path does not point to a directory and the parent directory exists.","Check filesystem permissions for the JVM process on the target path.","Investigate concurrent cleanup processes that may delete the file between creation and open.","Ensure the disk has free space and the filesystem is writable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File parent = file.getParentFile();\nif (parent != null && !parent.exists() && !parent.mkdirs()) {\n    throw new IOException(\"Cannot create parent directory: \" + parent);\n}\nif (file.exists() && file.isDirectory()) {\n    throw new IOException(\"Path is a directory, not a file: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ConcurrentDiskUtil.writeFileContent(file, content, charsetName);\n} catch (IOException e) {\n    if (\"file not exist\".equals(e.getMessage())) {\n        // retry once after ensuring the file and parent exist\n        file.getParentFile().mkdirs();\n        file.createNewFile();\n        ConcurrentDiskUtil.writeFileContent(file, content, charsetName);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Verify the file path is not a directory and the parent directory exists before writing.","Check filesystem permissions for the JVM process.","Investigate concurrent cleanup processes that may delete files during write."],"tags":["disk","file-io","concurrency","filesystem","client"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}