This repository was archived by the owner on Apr 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
Google Storage NIO: FileAlreadyExistsException exception is not honoured when overwriting files #762
Copy link
Copy link
Closed
Labels
api: storageIssues related to the googleapis/java-storage-nio API.Issues related to the googleapis/java-storage-nio API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Environment details
- Specify the API at the beginning of the title. For example, "BigQuery: ...").
General, Core, and Other are also allowed as types - OS type and version: any
- Java version: Java 8 and later
- storage_nio version(s): com.google.cloud:google-cloud-nio:0.122.0 and later
Steps to reproduce
- Create a file
foo.txtintomy-bucket - Create a file
bar.txtintomy-bucket - Copy
foo.txttobar.txt
Code example
given:
def foo = CloudStorageFileSystem.forBucket('nf-bucket').getPath('foo.txt')
def bar = CloudStorageFileSystem.forBucket('nf-bucket').getPath('bar.txt')
and:
Files.createFile(foo)
Files.createFile(bar)
when:
Files.copy(foo, bar)
then:
thrown(FileAlreadyExistsException)Stack trace
com.google.cloud.storage.StorageException: 412 Precondition Failed
PUT https://storage.googleapis.com/upload/storage/v1/b/nf-bucket/o?uploadType=resumable&name=foo.txt&ifGenerationMatch=0&upload_id=ADPycdtER9Udv5f3mdmhElr4rbAf-0U0L59G6pHmMw92d6SUtppicKL0slMnCdx8JhX1_2MPZo9MBUph1Q9NqQXuUjIUVoCeHQ
{
"error": {
"code": 412,
"message": "At least one of the pre-conditions you specified did not hold.",
"errors": [
{
"message": "At least one of the pre-conditions you specified did not hold.",
"domain": "global",
"reason": "conditionNotMet",
"locationType": "header",
"location": "If-Match"
}
]
}
}
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:231)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.writeWithResponse(HttpStorageRpc.java:822)
at com.google.cloud.storage.BlobWriteChannel$1.run(BlobWriteChannel.java:69)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.storage.BlobWriteChannel.flushBuffer(BlobWriteChannel.java:61)
at com.google.cloud.BaseWriteChannel.close(BaseWriteChannel.java:151)
at com.google.cloud.storage.contrib.nio.CloudStorageWriteChannel.close(CloudStorageWriteChannel.java:55)
at java.nio.file.Files.createFile(Files.java:632)
External references such as API reference guides
- Java docs Files.copy
Any additional information below
This work as expected up to version 0.121.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: storageIssues related to the googleapis/java-storage-nio API.Issues related to the googleapis/java-storage-nio API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.