{"record":{"id":"b5ee14c0138bbb0e","repo":"apache/iceberg","slug":"location-already-exists-s-b5ee14","errorCode":null,"errorMessage":"Location already exists: %s","messagePattern":"Location already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"azure/src/main/java/org/apache/iceberg/azure/adlsv2/ADLSOutputFile.java","lineNumber":52,"sourceCode":"      String location,\n      DataLakeFileClient fileClient,\n      AzureProperties azureProperties,\n      MetricsContext metrics) {\n    super(location, fileClient, azureProperties, metrics);\n  }\n\n  /**\n   * Create an output stream for the specified location if the target object does not exist in Azure\n   * at the time of invocation.\n   *\n   * @return output stream\n   */\n  @Override\n  public PositionOutputStream create() {\n    if (!exists()) {\n      return createOrOverwrite();\n    } else {\n      throw new AlreadyExistsException(\"Location already exists: %s\", location());\n    }\n  }\n\n  @Override\n  public PositionOutputStream createOrOverwrite() {\n    try {\n      return new ADLSOutputStream(fileClient(), azureProperties(), metrics());\n    } catch (IOException e) {\n      throw new UncheckedIOException(\n          \"Failed to create output stream for location: \" + location(), e);\n    }\n  }\n\n  @Override\n  public InputFile toInputFile() {\n    return new ADLSInputFile(location(), fileClient(), azureProperties(), metrics());\n  }\n}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/azure/src/main/java/org/apache/iceberg/azure/adlsv2/ADLSOutputFile.java#L34-L70","documentation":"ADLSOutputFile.create() refuses to overwrite an existing file: it checks existence first and throws AlreadyExistsException if the location already has content. Use createOrOverwrite() if overwriting is intended.","triggerScenarios":"Calling ADLSOutputFile.create() when a blob already exists at the target location.","commonSituations":"Retrying a failed write without cleaning up a partially created file; a leftover file from a previous job run; two writers targeting the same path.","solutions":["Delete the existing file or use a new unique file name/path.","Call createOrOverwrite() instead of create() if overwriting is acceptable.","Clean up stale output from previous failed runs before retrying the write."],"exampleFix":"// before\nPositionOutputStream out = outputFile.create();\n// after\nPositionOutputStream out = outputFile.createOrOverwrite(); // or ensure the file does not exist","handlingStrategy":"validation","validationCode":"if (outputFile.exists()) { // choose: delete, pick a new name, or use createOrOverwrite()\n}","typeGuard":null,"tryCatchPattern":"try { out = outputFile.create(); } catch (AlreadyExistsException e) { out = outputFile.createOrOverwrite(); // or generate a new unique path\n}","preventionTips":["Use unique, collision-resistant output paths (e.g. UUID-suffixed filenames) per write attempt.","Clean up leftover files from failed runs before retrying.","Use createOrOverwrite() deliberately when overwrite semantics are intended."],"tags":["azure","adls","file-exists","io"],"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"}