28

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;
}
1
  • 3
    You have multiple versions of Guava on your classpath. Figure out which of your dependencies depend on Guava, and make sure only one version remains.
    – Jorn
    Jul 21, 2017 at 22:35

7 Answers 7

38

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.

1
  • @Karl Richter, How and where should guava be defined in a Java app if we think there is a conflict between libraries? Can guava be overwritten as to only use one version? Sep 10, 2018 at 1:04
15

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>
0
3

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.

2

Try inserting a dependency containing a newer version of guava at the top of your dependencies in your pom.xml containing your project.

E.g.

  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>24.1.1-jre</version>
  </dependency>
1
  • thank you, that actually mattered, which I did not think it would :) May 3, 2021 at 8:39
2

For anybody encountering anything like this, i had the following pom:

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>3.2.1</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20190722</version>
</dependency>
<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.2</version>
</dependency>

And commenting out the maven-shade plugin fixed it for me...

1

I had the same issue in my Java/Kotlin application. When the app was ran via IntelliJ there were no issues. However, when the .Jar was ran the error message above was thrown.

I could not find a direct action item to take with the Guava issue defined by @Laurent Perez above so I did the following which resolved the issue with my .Jar file running:

  • Removed .Jar IntelliJ configurations and file from IntelliJ. Then re-added the .Jar following Step 3 from this deploy guide.

Other actions to try if the above does not work:

  • Rebuild project.
  • Invalidate IntelliJ cache and restart.
  • Restart computer.
1
  • Please don't make your answer dependent on an external link - copy the relevant parts, as the link can break at any time. Nov 16, 2020 at 16:41
1

It happens when you're missing guava library from your dependency. Add it using following in your pom.xml

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

Another reason could be there are multiple versions of google guava/collection library, you can't have both as mentioned by @sabbir in his comment, you ought to remove one of them.

Lastly it could be that some other dependency is dependent on the previous version of google guava/collections. Go to Dependency Hierarchy and search for google and see what all dependencies are dependent on the previous versions. In my case it was by version-maven-plugin, version 2.7

Here version-maven-plugin, version 2.7 uses google collections 1.0, and I require guava 24.0 Both can't work simuntaneously. enter image description here

I excluded it in my pom.xml like this and then added a new dependency of guava

    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.7</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.collections</groupId>
                <artifactId>google-collections</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

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

Resultant: Now google-collections is gone. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.