{"record":{"id":"6f130cc9c28a221c","repo":"apache/hadoop","slug":"path-already-exists","errorCode":null,"errorMessage":"{path} already exists","messagePattern":"(.+?) already exists","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java","lineNumber":132,"sourceCode":"  @Override\n  public FSDataOutputStream create(Path path, FsPermission permission,\n      boolean overwrite, int bufferSize, short replication, long blockSize,\n      Progressable progress) throws IOException {\n    String key = pathToKey(path);\n    FileStatus status = null;\n\n    try {\n      // get the status or throw a FNFE\n      status = getFileStatus(path);\n\n      // if the thread reaches here, there is something at the path\n      if (status.isDirectory()) {\n        // path references a directory\n        throw new FileAlreadyExistsException(path + \" is a directory\");\n      }\n      if (!overwrite) {\n        // path references a file and overwrite is disabled\n        throw new FileAlreadyExistsException(path + \" already exists\");\n      }\n      LOG.debug(\"Overwriting file {}\", path);\n    } catch (FileNotFoundException e) {\n      // this means the file is not found\n    }\n\n    return new FSDataOutputStream(\n        new AliyunOSSBlockOutputStream(getConf(),\n            store,\n            key,\n            uploadPartSize,\n            blockFactory,\n            blockOutputStreamStatistics,\n            new SemaphoredDelegatingExecutor(boundedThreadPool,\n                blockOutputActiveBlocks, true)), statistics);\n  }\n\n  /**","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java#L114-L150","documentation":"Thrown by AliyunOSSFileSystem.create(): the target path exists as a file and the caller did not set the overwrite flag, so the connector raises FileAlreadyExistsException(path + \" already exists\") to protect existing data.","triggerScenarios":"Calling create(path, /*overwrite*/ false, ...) when an object already exists at that key; re-running a job whose previous output object was not cleaned (e.g., failed commit, manually copied file).","commonSituations":"Re-executed Spark/MapReduce jobs writing to deterministic file names; FileOutputCommitter leftovers when a rerun uses the same output file name; shared output locations across teams where another writer created the object first.","solutions":["Pass overwrite=true when the intent is to replace the object: fs.create(path, true)","If overwrite is wrong (idempotent pipelines), delete or move the existing object before the run","Make output file names unique per run/attempt (append attempt id or timestamp) so reruns never collide"],"exampleFix":"// before\nfs.create(path, /*overwrite*/ false);\n\n// after\nfs.create(path, /*overwrite*/ true);","handlingStrategy":"validation","validationCode":"boolean overwrite = /* rerun policy */ true;\nif (!overwrite && fs.exists(path)) {\n  throw new IOException(\"Output already exists: \" + path);\n}\nfs.create(path, overwrite);","typeGuard":null,"tryCatchPattern":"catch (FileAlreadyExistsException e) { if (\"already exists\".in(e.getMessage())) { /* decide: delete stale object or rerun with overwrite */ } throw e; }","preventionTips":["Decide the overwrite policy explicitly at every create() call site","Use per-run unique file names for idempotent pipelines instead of relying on overwrite"],"tags":["aliyun-oss","file-exists","overwrite","hadoop-connector"],"backgroundTag":"output-file-already-exists","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}