{"record":{"id":"06d1cb77e653d60c","repo":"apache/seatunnel","slug":"file-already-exists-s","errorCode":null,"errorMessage":"File already exists: %s","messagePattern":"File already exists: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java","lineNumber":528,"sourceCode":"    @Override\n    public FSDataOutputStream create(\n            Path f,\n            FsPermission permission,\n            boolean overwrite,\n            int bufferSize,\n            short replication,\n            long blockSize,\n            Progressable progress)\n            throws IOException {\n        final ChannelSftp client = connect();\n        try {\n            Path workDir = new Path(client.pwd());\n            Path absolute = makeAbsolute(workDir, f);\n            if (exists(client, f)) {\n                if (overwrite) {\n                    delete(client, f, false);\n                } else {\n                    throw new IOException(String.format(E_FILE_EXIST, f));\n                }\n            }\n            Path parent = absolute.getParent();\n            if (parent == null || !mkdirs(client, parent, FsPermission.getDefault())) {\n                parent = (parent == null) ? new Path(\"/\") : parent;\n                throw new IOException(String.format(E_CREATE_DIR, parent));\n            }\n            final String previousCwd = client.pwd();\n            client.cd(parent.toUri().getPath());\n            OutputStream os = client.put(f.getName());\n            client.cd(previousCwd);\n            return new FSDataOutputStream(os, statistics) {\n                @Override\n                public void close() throws IOException {\n                    try {\n                        super.close();\n                    } finally {\n                        disconnect(client);","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java#L510-L546","documentation":"create() checks exists(client, f) and, when overwrite=false, throws IOException(E_FILE_EXIST) instead of replacing the file. Hadoop-compatible create semantics: an existing file is only deleted when overwrite is true; otherwise creation is refused.","triggerScenarios":"fs.create(path) (or connector sink setup creating the output file) where the target file already exists and the overwrite flag is false.","commonSituations":"Re-running a batch job against the same output path without cleanup; sink configured without overwrite enabled; leftover partial output from a failed run; two jobs writing the same target concurrently.","solutions":["Enable overwrite: fs.create(path, true) or set the connector's overwrite/replace option","Delete the existing file before creating: fs.delete(path, false)","Write to a unique output path per run (timestamped / attempt-scoped)","Check fs.exists(path) beforehand and fail fast with a clear message"],"exampleFix":"// before\nFSDataOutputStream out = fs.create(path, false);\n// after\nFSDataOutputStream out = fs.create(path, true);","handlingStrategy":"validation","validationCode":"Path out = new Path(\"/data/out/result\");\nif (fs.exists(out) && !overwriteAllowed) {\n    throw new IOException(\"Output exists, overwrite disabled: \" + out);\n}","typeGuard":null,"tryCatchPattern":"try {\n    FSDataOutputStream out = fs.create(path, false);\n} catch (IOException e) {\n    if (String.valueOf(e.getMessage()).contains(\"already exists\")) {\n        FSDataOutputStream out = fs.create(path, true); // if overwrite is acceptable\n    } else { throw e; }\n}","preventionTips":["Enable overwrite explicitly when re-running jobs is expected","Use unique output paths per run","Check fs.exists() before creating","Clean partial outputs from failed runs"],"tags":["sftp","create","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}