{"record":{"id":"5eac2d0b2abc576c","repo":"apache/hadoop","slug":"already-exists-5eac2d","errorCode":null,"errorMessage":"{} already exists","messagePattern":"(.+?) already exists","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSFileSystem.java","lineNumber":709,"sourceCode":"      final short replication,\n      final long blkSize,\n      final Progressable progress)\n      throws IOException {\n    String key = OBSCommonUtils.pathToKey(this, f);\n    FileStatus status;\n    long objectLen = 0;\n    try {\n      // get the status or throw an exception\n      status = getFileStatus(f);\n      objectLen = status.getLen();\n      // if the thread reaches here, there is something at the path\n      if (status.isDirectory()) {\n        // path references a directory: automatic error\n        throw new FileAlreadyExistsException(f + \" is a directory\");\n      }\n      if (!overwrite) {\n        // path references a file and overwrite is disabled\n        throw new FileAlreadyExistsException(f + \" already exists\");\n      }\n      LOG.debug(\"create: Overwriting file {}\", f);\n    } catch (FileNotFoundException e) {\n      // this means the file is not found\n      LOG.debug(\"create: Creating new file {}\", f);\n    }\n    return new FSDataOutputStream(\n        new OBSBlockOutputStream(\n            this,\n            key,\n            objectLen,\n            new SemaphoredDelegatingExecutor(\n                boundedMultipartUploadThreadPool,\n                blockOutputActiveBlocks, true),\n            false),\n        null);\n  }\n","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSFileSystem.java#L691-L727","documentation":"The sibling check in OBSFileSystem.create(...): the path exists as a file and the caller did not ask for overwrite, so the connector throws FileAlreadyExistsException(f + ' already exists'). This is the standard Hadoop FileSystem contract — create without overwrite must fail on an existing file — implemented before the OBSBlockOutputStream is constructed. Note the connector treats a FileNotFoundException from getFileStatus as 'safe to create', so the error strictly means an existing object was found.","triggerScenarios":"fs.create(path, false) or create(path) with default overwrite=false when the object already exists; re-running a job with output committed by an operation that bypasses the overwrite flag; passing overwrite=false implicitly via some FileSystem.create overloads or FileSystem.create(FileSystem,Path) helpers.","commonSituations":"Re-running pipelines without cleaning output; downstream consumers that write result files to deterministic paths; enablement of exactly-once semantics where the writer intentionally disallows overwrite but the file from attempt #1 survived.","solutions":["Pass overwrite=true when the semantics allow replacing the file: fs.create(path, true)","Or delete the existing object first: if (fs.exists(path)) fs.delete(path, false)","Or write to a unique path (append attempt id / timestamp) and rename atomically afterwards","Audit callers of FileSystem.create(...) helpers that default overwrite to false"],"exampleFix":"// before\nFSDataOutputStream out = fs.create(path); // existing file, default overwrite=false -> FileAlreadyExistsException\n\n// after\nFSDataOutputStream out = fs.create(path, true);","handlingStrategy":"validation","validationCode":"if (!overwrite && fs.exists(f) && fs.getFileStatus(f).isFile()) {\n  throw new FileAlreadyExistsException(f + \" already exists and overwrite is disabled\");\n}\nFSDataOutputStream out = fs.create(f, overwrite);","typeGuard":null,"tryCatchPattern":"try {\n  out = fs.create(f, false);\n} catch (FileAlreadyExistsException e) {\n  if (String.valueOf(e.getMessage()).endsWith(\"already exists\")) {\n    out = fs.create(f, true); // only if replace-on-rerun is acceptable\n  } else {\n    throw e;\n  }\n}","preventionTips":["Decide rerun semantics explicitly: overwrite=true, pre-delete, or unique paths","Audit helpers like FileSystem.create(fs, path) that default to overwrite=false","Use deterministic + attempt-id paths in exactly-once pipelines"],"tags":["create","overwrite","file-exists","hadoop-obs"],"backgroundTag":"file-already-exists","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}