{"record":{"id":"947315f6e358219d","repo":"apache/beam","slug":"this-filename-is-already-in-use","errorCode":null,"errorMessage":"This filename is already in use.","messagePattern":"This filename is already in use\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystem.java","lineNumber":282,"sourceCode":"                blobProperties.getContentEncoding(),\n                blobProperties.getETag())));\n  }\n\n  @Override\n  protected WritableByteChannel create(AzfsResourceId resourceId, CreateOptions createOptions)\n      throws IOException {\n    BlobContainerClient blobContainerClient =\n        client.get().getBlobContainerClient(resourceId.getContainer());\n    if (!blobContainerClient.exists()) {\n      throw new FileNotFoundException(\n          \"This container does not exist. Creating containers is not supported.\");\n    }\n\n    BlobClient blobClient = blobContainerClient.getBlobClient(resourceId.getBlob());\n    // The getBlobOutputStream method overwrites existing blobs,\n    // so throw an error in this case to prevent data loss\n    if (blobClient.exists()) {\n      throw new IOException(\"This filename is already in use.\");\n    }\n\n    OutputStream outputStream;\n    try {\n      outputStream = blobClient.getBlockBlobClient().getBlobOutputStream();\n    } catch (BlobStorageException e) {\n      throw (IOException) e.getCause();\n    }\n    return newChannel(outputStream);\n  }\n\n  @Override\n  protected ReadableByteChannel open(AzfsResourceId resourceId) throws IOException {\n    BlobContainerClient containerClient =\n        client.get().getBlobContainerClient(resourceId.getContainer());\n    if (!containerClient.exists()) {\n      throw new FileNotFoundException(\"The requested file doesn't exist.\");\n    }","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystem.java#L264-L300","documentation":"AzureBlobStoreFileSystem.create() checks whether the target blob already exists before opening an output stream, because Azure's getBlobOutputStream silently overwrites existing blobs. To prevent silent data loss, it throws this IOException when the destination filename is already taken. It is a deliberate safety guard against overwrite-on-create semantics.","triggerScenarios":"Calling FileSystem.create() (or Match/Write via the Beam filesystem layer) on an azfs:// path whose blob name already exists in the target container.","commonSituations":"Re-running a pipeline or job that writes to the same azfs output path without unique naming (e.g. missing timestamp/shard in output prefix); two concurrent writers racing to create the same blob; a user assuming create() behaves like put with overwrite.","solutions":["Delete the existing blob first (via FileSystem.delete or Azure portal/CLI) if overwrite is intended.","Choose a new destination filename or add a unique suffix/timestamp to the output path.","Copy the existing blob aside (backup) before recreating at the same name.","Check existence beforehand with FileSystem.match() and branch on the result."],"exampleFix":"// before\nFileSystem fnFs = FileSystems.matchNewResource(\"azfs://container/existing/blob.txt\", false);\nFileSystems.create(fnFs, CreateOptions.StandardCreateOptions.builder().build()); // throws if exists\n// after\nResourceId resourceId = FileSystems.matchNewResource(\"azfs://container/unique-run-2026-09-12/blob.txt\", false);\nFileSystems.create(resourceId, CreateOptions.StandardCreateOptions.builder().build());","handlingStrategy":"validation","validationCode":"ResourceId dst = FileSystems.matchNewResource(path, false);\nMatchResult m = FileSystems.match(path);\nif (m.status() == MatchResult.Status.OK && !m.metadata().isEmpty()) {\n  throw new IllegalStateException(\"Destination already exists: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileSystems.create(dst, createOptions);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"already in use\")) {\n    // switch to a unique name or handle overwrite explicitly\n  } else { throw e; }\n}","preventionTips":["Include run IDs or timestamps in output blob paths to keep them unique.","Call FileSystems.match() on the destination before create.","Never rely on create() to overwrite; treat existing destinations as an error condition."],"tags":["azure","blob-storage","file-already-exists","io","beam-filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}