{"record":{"id":"79a9150bfb234473","repo":"apache/iceberg","slug":"location-already-exists-s","errorCode":null,"errorMessage":"Location already exists: %s","messagePattern":"Location already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":409,"severity":"error","filePath":"aliyun/src/main/java/org/apache/iceberg/aliyun/oss/OSSOutputFile.java","lineNumber":46,"sourceCode":"\nclass OSSOutputFile extends BaseOSSFile implements OutputFile {\n\n  OSSOutputFile(OSS client, OSSURI uri, AliyunProperties aliyunProperties, MetricsContext metrics) {\n    super(client, uri, aliyunProperties, metrics);\n  }\n\n  static OSSOutputFile fromLocation(\n      OSS client, String location, AliyunProperties aliyunProperties) {\n    return new OSSOutputFile(\n        client, new OSSURI(location), aliyunProperties, MetricsContext.nullMetrics());\n  }\n\n  @Override\n  public PositionOutputStream create() {\n    if (!exists()) {\n      return createOrOverwrite();\n    } else {\n      throw new AlreadyExistsException(\"Location already exists: %s\", uri());\n    }\n  }\n\n  @Override\n  public PositionOutputStream createOrOverwrite() {\n    return new OSSOutputStream(client(), uri(), aliyunProperties(), metrics());\n  }\n\n  @Override\n  public InputFile toInputFile() {\n    return new OSSInputFile(client(), uri(), aliyunProperties(), metrics());\n  }\n}\n","sourceCodeStart":28,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aliyun/src/main/java/org/apache/iceberg/aliyun/oss/OSSOutputFile.java#L28-L60","documentation":"OSSOutputFile.create() first checks whether the target object already exists in OSS and throws AlreadyExistsException if it does. This prevents silently clobbering an existing data/manifest file, matching the FileIO contract that create() must not overwrite.","triggerScenarios":"Calling create() on an OSSOutputFile whose URI points to an object already present in the bucket; using create() instead of createOrOverwrite() to retry a failed write.","commonSituations":"Retrying a failed commit without cleaning up partial output; two writers racing to write the same file path; re-running a job with the same output location without deleting prior files.","solutions":["Use createOrOverwrite() if overwrite is intended.","Choose a unique output location (new metadata path/partition file name) before writing.","Delete the stale object if it is safe to replace.","Fix writer concurrency so only one task writes a given path."],"exampleFix":"// before\nPositionOutputStream out = outputFile.create();\n\n// after\nPositionOutputStream out = outputFile.createOrOverwrite();","handlingStrategy":"try-catch","validationCode":"if (outputFile.exists()) {\n  // pick a new path or delete intentionally before writing\n}","typeGuard":null,"tryCatchPattern":"try {\n  out = outputFile.create();\n} catch (AlreadyExistsException e) {\n  // choose a new file location or use createOrOverwrite()\n}","preventionTips":["Use createOrOverwrite() when replacement is intended.","Generate unique output paths (metadata LocationProvider handles this).","Avoid retrying writers without cleaning prior partial output.","Ensure one writer per file path (task affinity, not concurrent retry)."],"tags":["aliyun","oss","file-already-exists","fileio"],"backgroundTag":"file-already-exists","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}