Skip to content

Commit aa90468

Browse files
authored
fix: fix IllegalMonitorStateException thrown from BlobAppendableUpload.isOpen() (#3302)
FileChannel.transferTo first checks if the destination is open. Our tests didn't catch this before because they did not probe openness before writing bytes.
1 parent 34e797d commit aa90468

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobAppendableUploadImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public int write(ByteBuffer src) throws IOException {
111111

112112
@Override
113113
public boolean isOpen() {
114+
lock.lock();
114115
try {
115116
return buffered.isOpen();
116117
} finally {

google-cloud-storage/src/test/java/com/google/cloud/storage/ITAppendableUploadTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.google.cloud.storage;
1717

18-
import static com.google.cloud.storage.ByteSizeConstants._1MiB;
1918
import static com.google.cloud.storage.TestUtils.assertAll;
2019
import static com.google.cloud.storage.TestUtils.xxd;
2120
import static com.google.common.truth.Truth.assertThat;
@@ -44,6 +43,7 @@
4443
import com.google.cloud.storage.it.runner.registry.Generator;
4544
import com.google.common.base.MoreObjects;
4645
import com.google.common.collect.ImmutableList;
46+
import com.google.common.io.ByteStreams;
4747
import java.io.IOException;
4848
import java.nio.ByteBuffer;
4949
import java.nio.channels.SeekableByteChannel;
@@ -222,7 +222,7 @@ public void testUploadFileUsingAppendable() throws Exception {
222222
storage.blobAppendableUpload(BlobInfo.newBuilder(bid).build(), p.uploadConfig);
223223
try (SeekableByteChannel r = tmpFile.reader();
224224
AppendableUploadWriteableByteChannel w = appendable.open()) {
225-
long copied = Buffers.copyUsingBuffer(Buffers.allocate(8 * _1MiB), r, w);
225+
long copied = ByteStreams.copy(r, w);
226226
assertThat(copied).isEqualTo(fileSize);
227227
}
228228
BlobInfo bi = appendable.getResult().get(5, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)