Using Blob.listAcls() works on first invocation after the blob creation, but fails on second invocation after Blob.writer() was used to write the contents. To be able to use it, have to request Service for a new Blob instance without using BlobId of existing instnace. Please see the following reproducer code:
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import com.google.cloud.WriteChannel;
import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import org.testng.annotations.Test;
public class GcsAclReproducerTest {
@Test
public void test() throws Exception {
final String inputBucketName = UUID.randomUUID().toString();
final String inputBlobName = UUID.randomUUID().toString();
final Storage storageService = StorageOptions.getDefaultInstance().getService();
final Bucket bucket = storageService.create(BucketInfo.newBuilder(inputBucketName).build());
final Blob blob
= storageService.create(BlobInfo.newBuilder(inputBucketName, inputBlobName).build());
final List<Acl> acls1 = blob.listAcls();
assertNotNull(acls1);
assertFalse(acls1.isEmpty());
try (final WriteChannel writer = blob.writer()) {
final byte[] contents = new byte[1024 * 1024];
new Random().nextBytes(contents);
writer.write(ByteBuffer.wrap(contents));
}
final List<Acl> acls2 = blob.listAcls();
assertNotNull(acls2);
assertFalse(acls2.isEmpty());
}
}
Using
Blob.listAcls()works on first invocation after the blob creation, but fails on second invocation afterBlob.writer()was used to write the contents. To be able to use it, have to requestServicefor a newBlobinstance without usingBlobIdof existing instnace. Please see the following reproducer code: