Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V

What Google Maven dependency could fix this error:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:487)
    at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
    at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:94)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
    at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:124)
    at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
    at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
    at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
    at java.io.InputStream.read(InputStream.java:101)

Code:

Blob blob = storage.get(blobId);
if(blob.exists()) {
    return true;
}
like image 793
quarks Avatar asked Jul 21 '17 21:07

quarks


3 Answers

Your Google guava version is either too old (< 20.0) or mismatched (multiple jars versions). Make sure you don't have several versions in your dependency tree.

Use

mvn dependency:tree | less

to look for the guava versions.

like image 133
Laurent Perez Avatar answered Nov 13 '22 20:11

Laurent Perez


Please add following dependencies to your project's POM:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.6-jre</version>
</dependency> 
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.8</version>
</dependency>
like image 15
Avinash Pande Avatar answered Nov 13 '22 20:11

Avinash Pande


In my case, I happened to include both

    <dependency>
      <groupId>com.google.collections</groupId>
      <artifactId>google-collections</artifactId>
      <version>1.0</version>
    </dependency>

and

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>28.0-jre</version>
    </dependency>

As it turns out, I cannot use both of these libraries. Removing google-collections fixed the issue for me.

like image 3
sabbir Avatar answered Nov 13 '22 20:11

sabbir