Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument #5258

Closed
CptanPanic opened this issue Jan 18, 2019 · 8 comments

Comments

@CptanPanic
Copy link

Please answer these questions before submitting your issue.

What version of gRPC are you using?

1.17.2, built jars, etc using gradle. Java 1.8.0

What did you expect to see?

I am unable to create simple grpc objects, both in Matlab and another proprietary java application and get similar NoSuchMethodError errors.

Issue Description

So initially I am trying to get grpc-java to run in matlab, but when I tried 'o = io.grpc.ManagedChannelBuilder.forAddress('localhost', 5001)' I get the following error:

Java exception occurred:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
        at io.grpc.Metadata$Key.validateName(Metadata.java:630)
        at io.grpc.Metadata$Key.<init>(Metadata.java:638)
        at io.grpc.Metadata$Key.<init>(Metadata.java:568)
        at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:743)
        at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:738)
        at io.grpc.Metadata$Key.of(Metadata.java:594)
        at io.grpc.Metadata$Key.of(Metadata.java:590)
        at io.grpc.internal.GrpcUtil.<clinit>(GrpcUtil.java:84)
        at io.grpc.internal.AbstractManagedChannelImplBuilder.<clinit>(AbstractManagedChannelImplBuilder.java:83)
        at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
        at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
        at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:37)

What is interesting, I was able to get past that initial error by adding 'import io.grpc.Metadata', but still ended up with the following error:

Java exception occurred:
java.lang.NoClassDefFoundError: Could not initialize class io.grpc.netty.NettyChannelBuilder
        at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
        at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
        at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:37)

Which didn't make any sense to me since I can build and run code on command line using same jars. So I submitted a ticket to Mathworks, and they are looking at it.

But what led me to open this ticket, is in parellel we are adding grpc-java support to another java product, that allows us to create our own plugins, and after adding grpc-java to our code, now on startup we now get the following similar error in this tool, so now I think this isn't a Matlab thing, but something else that is wrong either with something I am doing, or the code. Any ideas?

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
                at io.grpc.Metadata$Key.validateName(Metadata.java:630)
                at io.grpc.Metadata$Key.<init>(Metadata.java:638)
                at io.grpc.Metadata$Key.<init>(Metadata.java:568)
                at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:743)
                at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:738)
                at io.grpc.Metadata$Key.of(Metadata.java:594)
                at io.grpc.Metadata$Key.of(Metadata.java:590)
                at io.grpc.internal.GrpcUtil.<clinit>(GrpcUtil.java:84)
                at io.grpc.internal.AbstractManagedChannelImplBuilder.<clinit>(AbstractManagedChannelImplBuilder.java:83)
                at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
                at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
                at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:37)
                at custom.tool.myplugin.managers.GrpcManager.initChannel(GrpcManager.java:48)
                at custom.tool.myplugin.managers.GrpcManager.init(GrpcManager.java:42)
                at custom.tool.myplugin.managers.MessageManager.init(MessageManager.java:68)
                at custom.tool.myplugin.mypluginManifest.fillClassLists(mypluginManifest.java:116)
                at custom.tool.core.plugin_framework.AbstractModuleManifest.initialize(AbstractModuleManifest.java:178)
                at custom.tool.core.plugin_framework.AbstractModuleManifest.<init>(AbstractModuleManifest.java:174)
                at custom.tool.myplugin.mypluginManifest.<init>(mypluginManifest.java:36)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                at java.lang.Class.newInstance(Class.java:442)
                at custom.tool.core.plugin_framework.PluginModule.scanJarForPluginManifest(PluginModule.java:633)
                at custom.tool.core.plugin_framework.PluginModule.initializePluginManifest(PluginModule.java:578)
                at custom.tool.core.plugin_framework.PluginModule.scan(PluginModule.java:368)
                at custom.tool.core.plugin_framework.PluginModuleLoader.findAndLoadPluginModules(PluginModuleLoader.java:127)
                at custom.tool.core.TopsideApplication.lambda$initializePluginModules$9(TopsideApplication.java:759)
                at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
                at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
                at java.awt.EventQueue.access$500(EventQueue.java:97)
                at java.awt.EventQueue$3.run(EventQueue.java:709)
                at java.awt.EventQueue$3.run(EventQueue.java:703)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
                at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
                at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
                at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
                at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
                at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@carl-mastrangelo
Copy link
Contributor

I'm not familiar with how Matlab interacts with Java, so perhaps you can answer some questions:

  1. Are you using the io.grpc:grpc-all artifact from maven? Are you only using pieces?

  2. Are the Guava jars on the classpath? can you list all the jars on your class path? It seems like some how they are not being included.

  3. Can you list what versions of which jars you are using? If not using jars, are the flat files in the classpath?

  4. What version of Java is Matlab using?

@CptanPanic
Copy link
Author

I am using the collected jars that were downloaded and built by gradle. Matlab has a classpath.txt file which you list all the jars that are to be part of the classpath. So see below for all the jars that I got from gradle and have added to matlab classpath.

I did verify that I could build an example grpc client using just this jar directory.

  1. javac -classpath ../grpc-java-jars/*: -verbose MyClient.java
  2. java -cp .:../grpc-java-jars/* MyClient
/mnt/fileserver/myproject/grpc-java-jars/animal-sniffer-annotations-1.17.jar
/mnt/fileserver/myproject/grpc-java-jars/checker-compat-qual-2.5.2.jar
/mnt/fileserver/myproject/grpc-java-jars/commons-codec-1.3.jar
/mnt/fileserver/myproject/grpc-java-jars/commons-lang3-3.5.jar
/mnt/fileserver/myproject/grpc-java-jars/commons-logging-1.1.1.jar
/mnt/fileserver/myproject/grpc-java-jars/error_prone_annotations-2.2.0.jar
/mnt/fileserver/myproject/grpc-java-jars/examples.jar
/mnt/fileserver/myproject/grpc-java-jars/google-auth-library-credentials-0.9.0.jar
/mnt/fileserver/myproject/grpc-java-jars/google-auth-library-oauth2-http-0.9.0.jar
/mnt/fileserver/myproject/grpc-java-jars/google-http-client-1.19.0.jar
/mnt/fileserver/myproject/grpc-java-jars/google-http-client-jackson2-1.19.0.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-alts-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-auth-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-context-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-core-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-grpclb-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-netty-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-netty-shaded-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-protobuf-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-protobuf-lite-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/grpc-stub-1.17.1.jar
/mnt/fileserver/myproject/grpc-java-jars/gson-2.7.jar
/mnt/fileserver/myproject/grpc-java-jars/guava-26.0-android.jar
/mnt/fileserver/myproject/grpc-java-jars/httpclient-4.0.1.jar
/mnt/fileserver/myproject/grpc-java-jars/httpcore-4.0.1.jar
/mnt/fileserver/myproject/grpc-java-jars/j2objc-annotations-1.1.jar
/mnt/fileserver/myproject/grpc-java-jars/jackson-core-2.1.3.jar
/mnt/fileserver/myproject/grpc-java-jars/jsr305-3.0.2.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-buffer-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-http2-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-http-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-socks-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-common-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-handler-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-handler-proxy-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-resolver-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-tcnative-boringssl-static-2.0.17.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/netty-transport-4.1.30.Final.jar
/mnt/fileserver/myproject/grpc-java-jars/opencensus-api-0.17.0.jar
/mnt/fileserver/myproject/grpc-java-jars/opencensus-contrib-grpc-metrics-0.17.0.jar
/mnt/fileserver/myproject/grpc-java-jars/protobuf-java-3.5.1.jar
/mnt/fileserver/myproject/grpc-java-jars/protobuf-java-util-3.5.1.jar
/mnt/fileserver/myproject/grpc-java-jars/proto-google-common-protos-1.0.0.jar

@carl-mastrangelo
Copy link
Contributor

@CptanPanic The "NoClassDefFoundError" is almost certainly due to static initialization failing due to io.netty not being present. Are the dependencies of gRPC also present on the classpath? (particularly netty and guava?)

@CptanPanic
Copy link
Author

@carl-mastrangelo , are there more depencies for netty and guava that are not part of the above list? So I see that only guava-26.0-android.jar, should there be another more general guava? Also there are netty-*.jar files.

@carl-mastrangelo
Copy link
Contributor

d'oh! You are right, I only read the "grpc-java-jars" part. Another dumb question: are there multiple class loaders at play? The System class loader may not be the one you are using. If are using jdk9+, I think you can set -Xlog:class+load=trace to see what classes are actually being loaded.

@CptanPanic
Copy link
Author

So here is the jars that were loaded for the standalone executable. But overall there is not any jars except the rt.jar ones that are needed that are not being loaded.

/mnt/fileserver/myproject/grpc-java-jars/grpc-context-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-core-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-grpclb-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-netty-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-netty-shaded-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-protobuf-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-protobuf-lite-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/grpc-stub-1.17.1.jar]
/mnt/fileserver/myproject/grpc-java-jars/guava-26.0-android.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-buffer-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-http-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-codec-http2-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-common-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-handler-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-resolver-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/netty-transport-4.1.30.Final.jar]
/mnt/fileserver/myproject/grpc-java-jars/opencensus-api-0.17.0.jar]
/mnt/fileserver/myproject/grpc-java-jars/opencensus-contrib-grpc-metrics-0.17.0.jar]
/mnt/fileserver/myproject/grpc-java-jars/protobuf-java-3.5.1.jar]
/usr/java/jdk1.8.0_162/jre/lib/rt.jar

@CptanPanic
Copy link
Author

I have been working with Mathworks, and it turns out this is a problem with different versions of guava being used for my library, and matlab's internal use. They said it might work if gRPC used guava v24, which I don't think is possible anymore.

@ejona86
Copy link
Member

ejona86 commented Mar 6, 2019

This seems like a problem with the Mathworks platform, as it exposes its dependencies in the ClassPath. @CptanPanic, you may try making a "uber" jar containing your code and your dependencies and then shading Guava; that may have success, but would also be a bit painful to get all the configuration right. But it doesn't seem there's much more we can do to help you.

@ejona86 ejona86 closed this as completed Mar 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants