Guava version compatibility issue

Spring Boot errors

An attempt was made to call the method 
com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V 
but it does not exist
An attempt was made to call the method 
com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V 
but it does not exist
An attempt was made to call the method 
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService; 
but it does not exist

Pure Java exceptions

java.lang.NoSuchMethodError: 
com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
java.lang.NoSuchMethodError: 
com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
java.lang.NoSuchMethodError: 
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;

Suggested solutions

MethodGuava version
com.google.common.base.Preconditions.checkArgument26.0-jre / 26.0-android
com.google.common.base.Preconditions.checkState21.0
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor18.0 / 19.0

Let me remind you that guava with maven is connected like this:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>version_here</version>
</dependency>

If suggested verions don’t fix the problem, you can try connecting the specified versions in order: 18.0 / 19.0 / 21.0 / 26.0-jre / 26.0-android.

If this does not help, it means that there are conflicting libraries in the project. In my case, Apache Curator library required version 18, and gRPC required version 26.0-android.

This is solved by updating the version of the library that uses the old version of guava. I updated the Apache Curator version and it worked.
This was figured out thanks to the fact that I built the maven dependency structure with this command:

mvn dependency:tree

If you need a settings file for maven to work, you can add the settings flag:

mvn dependency:tree -settings.xml
Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *