'java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream trying to call storage.createFrom
I'm getting "java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)" when im calling create or createFrom on a com.google.cloud.storage.Storage object. I am trying to simply put a file in a bucket
My maven dependency is
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.6.1</version>
</dependency>
and my code looks like this
GoogleCredentials googleCredentails =
ServiceAccountCredentials.fromStream(new FileInputStream("credentials.json"));
Storage storage = StorageOptions.newBuilder()
.setCredentials(googleCredentails)
.setProjectId(projectId).build().getService();
BlobId blobId = BlobId.of(bucketName, objectName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
storage.createFrom(blobInfo, Paths.get(filePath));
Full error stack:
com.google.cloud.storage.StorageException: Unexpected error refreshing access token
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:286)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.open(HttpStorageRpc.java:1002)
at com.google.cloud.storage.ResumableMedia.lambda$null$0(ResumableMedia.java:37)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:103)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.storage.Retrying.run(Retrying.java:54)
at com.google.cloud.storage.ResumableMedia.lambda$startUploadForBlobInfo$1(ResumableMedia.java:34)
at com.google.cloud.storage.BlobWriteChannel$Builder.build(BlobWriteChannel.java:315)
at com.google.cloud.storage.StorageImpl.writer(StorageImpl.java:579)
at com.google.cloud.storage.StorageImpl.writer(StorageImpl.java:549)
at com.google.cloud.storage.StorageImpl.createFrom(StorageImpl.java:234)
at com.google.cloud.storage.StorageImpl.createFrom(StorageImpl.java:218)
at com.google.cloud.storage.StorageImpl.createFrom(StorageImpl.java:208)
at GCPIntegrationApp.onRun(GCPIntegrationApp.java:58)
Caused by: java.io.IOException: Unexpected error refreshing access token
at com.google.auth.oauth2.OAuth2Credentials.unwrapDirectFuture(OAuth2Credentials.java:323)
at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:170)
at com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadata(ServiceAccountCredentials.java:967)
at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:96)
at com.google.cloud.http.HttpTransportOptions$1.initialize(HttpTransportOptions.java:159)
at com.google.cloud.http.CensusHttpModule$CensusHttpRequestInitializer.initialize(CensusHttpModule.java:109)
at com.google.cloud.storage.spi.v1.HttpStorageRpc$InvocationIdInitializer.initialize(HttpStorageRpc.java:141)
at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:91)
at com.google.api.client.http.HttpRequestFactory.buildPostRequest(HttpRequestFactory.java:128)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.open(HttpStorageRpc.java:991)
... 16 more
Caused by: java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J
at com.google.api.client.http.ConsumingInputStream.close(ConsumingInputStream.java:40)
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:180)
at java.base/java.util.zip.InflaterInputStream.close(InflaterInputStream.java:232)
at java.base/java.util.zip.GZIPInputStream.close(GZIPInputStream.java:137)
at java.base/java.io.BufferedInputStream.close(BufferedInputStream.java:489)
at java.base/sun.nio.cs.StreamDecoder.implClose(StreamDecoder.java:378)
at java.base/sun.nio.cs.StreamDecoder.close(StreamDecoder.java:193)
at java.base/java.io.InputStreamReader.close(InputStreamReader.java:200)
at com.google.gson.stream.JsonReader.close(JsonReader.java:1219)
at com.google.api.client.json.gson.GsonParser.close(GsonParser.java:51)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:363)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:335)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:460)
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:572)
at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:257)
at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:254)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
at com.google.auth.oauth2.OAuth2Credentials$AsyncRefreshResult.executeIfNew(OAuth2Credentials.java:580)
at com.google.auth.oauth2.OAuth2Credentials.asyncFetch(OAuth2Credentials.java:220)
... 25 more
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
