0

I am getting this error, even after trying different versions of jars available and unable to find the Preconditions class in my intelliJ workspace.
Not sure why this method is getting called. I'm getting this runtime exception every time i run the code.
I am trying grpc and protobuffers for the first time but I'm not sure what to do about the below error.

"main" java.lang.NoSuchMethodError: 
'void com.google.common.base.Preconditions.checkArgument(  
         boolean, java.lang.String, char, java.lang.Object)'

My dependencies look like this:

 <dependencies>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-all</artifactId>
            <version>1.29.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.auto.value</groupId>
            <artifactId>auto-value-annotations</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.8</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.49.Final</version>
        </dependency>
    </dependencies>

And my mvn dependency:tree o/p is below.

[INFO] +- io.grpc:grpc-all:jar:1.29.0:compile
[INFO] |  +- io.grpc:grpc-api:jar:1.29.0:compile (version selected from constraint [1.29.0,1.29.0])
[INFO] |  +- io.grpc:grpc-auth:jar:1.29.0:compile
[INFO] |  |  \- com.google.auth:google-auth-library-credentials:jar:0.20.0:compile
[INFO] |  +- io.grpc:grpc-context:jar:1.29.0:compile
[INFO] |  +- io.grpc:grpc-core:jar:1.29.0:compile (version selected from constraint [1.29.0,1.29.0])
[INFO] |  |  +- com.google.code.gson:gson:jar:2.8.6:compile
[INFO] |  |  +- com.google.android:annotations:jar:4.1.1.4:compile
[INFO] |  |  \- io.perfmark:perfmark-api:jar:0.19.0:compile
[INFO] |  +- io.grpc:grpc-grpclb:jar:1.29.0:compile
[INFO] |  |  +- com.google.protobuf:protobuf-java:jar:3.11.0:compile
[INFO] |  |  \- com.google.protobuf:protobuf-java-util:jar:3.11.0:compile
[INFO] |  +- io.grpc:grpc-netty:jar:1.29.0:compile
[INFO] |  |  +- io.netty:netty-codec-http2:jar:4.1.48.Final:compile (version selected from constraint [4.1.48.Final,4.1.48.Final])
[INFO] |  |  |  +- io.netty:netty-common:jar:4.1.48.Final:compile
[INFO] |  |  |  +- io.netty:netty-buffer:jar:4.1.48.Final:compile
[INFO] |  |  |  +- io.netty:netty-transport:jar:4.1.48.Final:compile
[INFO] |  |  |  |  \- io.netty:netty-resolver:jar:4.1.48.Final:compile
[INFO] |  |  |  +- io.netty:netty-codec:jar:4.1.48.Final:compile
[INFO] |  |  |  +- io.netty:netty-handler:jar:4.1.48.Final:compile
[INFO] |  |  |  \- io.netty:netty-codec-http:jar:4.1.48.Final:compile
[INFO] |  |  \- io.netty:netty-handler-proxy:jar:4.1.48.Final:compile
[INFO] |  |     \- io.netty:netty-codec-socks:jar:4.1.48.Final:compile
[INFO] |  +- io.grpc:grpc-okhttp:jar:1.29.0:compile
[INFO] |  |  +- com.squareup.okio:okio:jar:1.13.0:compile
[INFO] |  |  \- com.squareup.okhttp:okhttp:jar:2.7.4:compile
[INFO] |  +- io.grpc:grpc-protobuf:jar:1.29.0:compile
[INFO] |  |  +- com.google.api.grpc:proto-google-common-protos:jar:1.17.0:compile
[INFO] |  |  \- io.grpc:grpc-protobuf-lite:jar:1.29.0:compile
[INFO] |  +- io.grpc:grpc-services:jar:1.29.0:compile
[INFO] |  +- io.grpc:grpc-stub:jar:1.29.0:compile
[INFO] |  +- io.grpc:grpc-testing:jar:1.29.0:compile
[INFO] |  |  \- io.opencensus:opencensus-api:jar:0.24.0:compile
[INFO] |  \- io.grpc:grpc-xds:jar:1.29.0:compile
[INFO] |     +- io.grpc:grpc-alts:jar:1.29.0:compile
[INFO] |     |  +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] |     |  +- org.conscrypt:conscrypt-openjdk-uber:jar:2.2.1:compile
[INFO] |     |  \- com.google.auth:google-auth-library-oauth2-http:jar:0.20.0:compile
[INFO] |     |     +- com.google.http-client:google-http-client:jar:1.34.0:compile
[INFO] |     |     |  +- org.apache.httpcomponents:httpclient:jar:4.5.10:compile
[INFO] |     |     |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |     |     |  |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] |     |     |  \- io.opencensus:opencensus-contrib-http-util:jar:0.24.0:compile
[INFO] |     |     \- com.google.http-client:google-http-client-jackson2:jar:1.34.0:compile
[INFO] |     |        \- com.fasterxml.jackson.core:jackson-core:jar:2.10.1:compile
[INFO] |     +- io.opencensus:opencensus-proto:jar:0.2.0:compile
[INFO] |     \- io.grpc:grpc-netty-shaded:jar:1.29.0:compile (version selected from constraint [1.29.0,1.29.0])
[INFO] +- com.google.auto.value:auto-value-annotations:jar:1.6.2:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- commons-cli:commons-cli:jar:1.4:compile
[INFO] +- com.google.guava:guava:jar:22.0:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.4.8:compile
[INFO] \- io.netty:netty-all:jar:4.1.49.Final:compile

I have checked the existing posts as well on this issue but none seems to be working for me. I believe there might be some issue with the versions but all the versions seem to be giving this error only.

lucidbrot
  • 5,378
  • 3
  • 39
  • 68
ankit
  • 51
  • 2
  • 8
  • I have absolutely no knowledge with gprc, but [this similar QA](https://stackoverflow.com/questions/42206440/java-lang-nosuchmethoderror-com-google-common-base-preconditions-checkargument) uses version `23.6-jre` of guava, and it is already more than two years old. Can you use newer versions? – lucidbrot May 05 '20 at 11:39
  • 1
    used - 29.0-jre,still not working – ankit May 05 '20 at 11:45
  • Then I cannot help further, sorry. But I'd advise you to reduce your code to a [mcve] - either you'll figure it out in the process or somebody on here will be better able to help you with it when you post that – lucidbrot May 05 '20 at 12:02

1 Answers1

4

Problem with a 3rd Party Library:

"main" java.lang.NoSuchMethodError: 
'void com.google.common.base.Preconditions.checkArgument(  
         boolean, java.lang.String, char, java.lang.Object)'

Let's try to update guava

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>21.0</version>
    </dependency>
c-quark
  • 37
  • 3