{"record":{"id":"728bcde9892e16f5","repo":"juicedata/juicefs","slug":"path-already-exists-f","errorCode":null,"errorMessage":"Path already exists: \" + f","messagePattern":"Path already exists: \" \\+ f","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java","lineNumber":1472,"sourceCode":"        return superGroupFileSystem.create(f, permission, overwrite, bufferSize, replication, blockSize, progress);\n      } else if (!checkPathAccess(f, FsAction.WRITE, \"create\")) {\n        return superGroupFileSystem.create(f, permission, overwrite, bufferSize, replication, blockSize, progress);\n      }\n    }\n    statistics.incrementWriteOps(1);\n    while (true) {\n      int fd = lib.jfs_create(Thread.currentThread().getId(), handle, normalizePath(f), permission.toShort(), uMask.toShort());\n      if (fd == ENOENT) {\n        Path parent = makeQualified(f).getParent();\n        try {\n          mkdirs(parent, FsPermission.getDirDefault());\n        } catch (FileAlreadyExistsException e) {\n        }\n        continue;\n      }\n      if (fd == EEXIST) {\n        if (!overwrite || isDirectory(f)) {\n          throw new FileAlreadyExistsException(\"Path already exists: \" + f);\n        }\n        delete(f, false);\n        continue;\n      }\n      if (fd < 0) {\n        throw error(fd, makeQualified(f).getParent());\n      }\n      return createFsDataOutputStream(f, bufferSize, fd, 0L);\n    }\n  }\n\n  private int checkBufferSize(int size) {\n    if (size < minBufferSize) {\n      size = minBufferSize;\n    }\n    return size;\n  }\n","sourceCodeStart":1454,"sourceCodeEnd":1490,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java#L1454-L1490","documentation":"Thrown by append() when the native jfs_open (append mode) returns EEXIST, i.e. the target path already exists, and the caller did not request overwrite (or the path is a directory). This mirrors Hadoop's FileAlreadyExistsException contract for append/create conflicts.","triggerScenarios":"append(f) called on a path that exists while overwrite is false; append with overwrite=true but the target is an existing directory; two writers racing to append/create the same path.","commonSituations":"Job retries re-attempting an append to a file from a previous failed attempt; treating an existing directory path as a file target; concurrent tasks writing to the same output path without unique names.","solutions":["Delete the existing file first or pass overwrite=true when the target is a regular file","Use a unique target name (part-<attemptId>) to avoid collisions on retries","Check exists(f) && !isDirectory(f) before appending","Catch FileAlreadyExistsException and branch to a new path or resume logic"],"exampleFix":"// before\nFSDataOutputStream out = fs.append(path); // throws if exists\n// after\nif (fs.exists(path)) { fs.delete(path, false); }\nFSDataOutputStream out = fs.append(path);","handlingStrategy":"try-catch","validationCode":"if (fs.exists(path) && fs.isDirectory(path)) throw new IllegalArgumentException(\"target is a directory: \" + path);","typeGuard":null,"tryCatchPattern":"try { return fs.append(path); } catch (FileAlreadyExistsException e) { fs.delete(path, false); return fs.append(path); }","preventionTips":["Check existence before append","Use unique per-attempt file names","Ensure overwrite flag matches intent","Never append to directory paths"],"tags":["java","hadoop","file-already-exists"],"backgroundTag":"file-already-exists","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}