Google-cloud-java: java.lang.AbstractMethodError: io.grpc.netty.NettyChannelBuilder$NettyTransportFactory.getScheduledExecutorService()Ljava/util/concurrent/ScheduledExecutorService;

Created on 27 Jul 2018  路  6Comments  路  Source: googleapis/google-cloud-java

I encountered the following stacktrace after I included "com.google.cloud" % "google-cloud-pubsub" % "1.37.1" in my project:

Caused by: java.lang.NoSuchMethodError: io.grpc.okhttp.OkHttpChannelProvider.isAndroid()Z
    at io.grpc.okhttp.OkHttpChannelProvider.priority(OkHttpChannelProvider.java:47) ~[grpc-okhttp-1.0.1.jar:1.0.1]
    at io.grpc.ManagedChannelProvider$1.getPriority(ManagedChannelProvider.java:49) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.ManagedChannelProvider$1.getPriority(ManagedChannelProvider.java:41) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.ServiceProviders$1.compare(ServiceProviders.java:78) ~[grpc-core-1.13.1.jar:1.13.1]
    at java.util.Collections$ReverseComparator2.compare(Collections.java:5178) ~[na:1.8.0_131]
    at java.util.TimSort.countRunAndMakeAscending(TimSort.java:360) ~[na:1.8.0_131]
    at java.util.TimSort.sort(TimSort.java:220) ~[na:1.8.0_131]
    at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_131]
    at java.util.ArrayList.sort(ArrayList.java:1454) ~[na:1.8.0_131]
    at java.util.Collections.sort(Collections.java:175) ~[na:1.8.0_131]

I then thought that the grpc-okhttp perhaps needed an upgrade, since it did not match the version of grpc-core, but upgrading resulted in another stacktrace:

Caused by: java.lang.AbstractMethodError: io.grpc.netty.NettyChannelBuilder$NettyTransportFactory.getScheduledExecutorService()Ljava/util/concurrent/ScheduledExecutorService;
    at io.grpc.internal.CallCredentialsApplyingTransportFactory.getScheduledExecutorService(CallCredentialsApplyingTransportFactory.java:54) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:576) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:410) ~[grpc-core-1.13.1.jar:1.13.1]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:206) ~[gax-grpc-1.29.0.jar:1.29.0]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:157) ~[gax-grpc-1.29.0.jar:1.29.0]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:149) ~[gax-grpc-1.29.0.jar:1.29.0]
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:151) ~[gax-1.29.0.jar:1.29.0]
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:116) ~[gax-1.29.0.jar:1.29.0]
    at com.google.cloud.logging.spi.v2.GrpcLoggingRpc.<init>(GrpcLoggingRpc.java:127) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at com.google.cloud.logging.LoggingOptions$DefaultLoggingRpcFactory.create(LoggingOptions.java:64) ~[google-cloud-logging-1.37.1.jar:1.37.1]

The dependencies in build.sbt currently look like this:

libraryDependencies ++= Seq(
  "com.google.cloud" % "google-cloud-core" % "1.37.1",
  jdbc,
  cache,
  ws,
  evolutions,
  "mysql" % "mysql-connector-java" % "5.1.28",
  "com.google.cloud.sql" % "mysql-socket-factory" % "1.0.2",
  "com.roundeights" %% "hasher" % "1.2.0",
  "io.intercom" % "intercom-java" % "2.3.3",
  "com.mixpanel" % "mixpanel-java" % "1.4.2",
  "eu.inn" %% "fluentd-scala" % "0.1.13",
  "com.typesafe.play" %% "anorm" % "2.4.0",
  "com.google.firebase" % "firebase-admin" % "4.0.3",
  "org.specs2" %% "specs2-core" % "3.6.2" % "test",
  "us.raudi.pushraven" % "Pushraven" % "1.0.2",
  "com.google.cloud" % "google-cloud-speech" % "0.20.1-alpha",
  "com.google.auth" % "google-auth-library-oauth2-http" % "0.6.0",
  "com.google.cloud" % "google-cloud-logging" % "1.37.1",
  "com.google.guava" % "guava" % "25.1-jre",
  "com.github.rishabh9" %% "mdc-propagation-dispatcher" % "0.0.5",
  "com.github.nscala-time" %% "nscala-time" % "2.18.0",
  "com.google.cloud" % "google-cloud-datastore" % "1.14.0",
  "com.github.davidmoten" % "geo" % "0.7.1",
  "com.danielasfregola" %% "twitter4s" % "3.0",
  "com.google.cloud" % "google-cloud-pubsub" % "1.37.1"
)

libraryDependencies += specs2 % Test

Any idea what might be wrong?

pubsub dependencies grpc question

All 6 comments

Try this:

  // Exclusion rules
  val exclusionRules = Seq(
    ExclusionRule("io.grpc", "grpc-okhttp"),
    ExclusionRule("io.grpc", "grpc-netty"),
    ExclusionRule( "io.grpc", "grpc-core")
  )

  libraryDependencies ++= Seq(
    "com.google.cloud" % "google-cloud-core" % "1.37.1",
    jdbc,
    cache,
    ws,
    evolutions,
    "mysql" % "mysql-connector-java" % "5.1.28",
    "com.google.cloud.sql" % "mysql-socket-factory" % "1.0.2" excludeAll(exclusionRules:_*), 
    "com.roundeights" %% "hasher" % "1.2.0",
    "io.intercom" % "intercom-java" % "2.3.3",
    "com.mixpanel" % "mixpanel-java" % "1.4.2",
    "eu.inn" %% "fluentd-scala" % "0.1.13",
    "com.typesafe.play" %% "anorm" % "2.4.0",
    "com.google.firebase" % "firebase-admin" % "4.0.3" excludeAll(exclusionRules:_*),
    "org.specs2" %% "specs2-core" % "3.6.2" % "test",
    "us.raudi.pushraven" % "Pushraven" % "1.0.2",
    "com.google.cloud" % "google-cloud-speech" % "0.20.1-alpha" excludeAll(exclusionRules:_*),
    "com.google.auth" % "google-auth-library-oauth2-http" % "0.6.0" excludeAll(exclusionRules:_*),
    "com.google.cloud" % "google-cloud-logging" % "1.37.1" excludeAll(exclusionRules:_*),
    "com.google.guava" % "guava" % "25.1-jre" excludeAll(exclusionRules:_*),
    "com.github.rishabh9" %% "mdc-propagation-dispatcher" % "0.0.5",
    "com.github.nscala-time" %% "nscala-time" % "2.18.0",
    "com.google.cloud" % "google-cloud-datastore" % "1.14.0" excludeAll(exclusionRules:_*),
    "com.github.davidmoten" % "geo" % "0.7.1",
    "com.danielasfregola" %% "twitter4s" % "3.0",
    "com.google.cloud" % "google-cloud-pubsub" % "1.37.1"
  )

  libraryDependencies += specs2 % Test

I have added exclusion rules to all google-cloud dependency. You may try to remove one by one to see which dependency is injecting the conflicting io.grpc.netty version.

Thanks for your help!
When I tried it, I first got this stackstrace:

Caused by: java.lang.ClassNotFoundException: io.grpc.internal.SharedResourceHolder$Resource
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131]
    at com.google.cloud.logging.LoggingOptions.getDefaultGrpcTransportOptions(LoggingOptions.java:125) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at com.google.cloud.logging.LoggingOptions$LoggingDefaults.getDefaultTransportOptions(LoggingOptions.java:120) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:288) ~[google-cloud-core-1.37.1.jar:1.37.1]
    at com.google.cloud.logging.LoggingOptions.<init>(LoggingOptions.java:102) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at com.google.cloud.logging.LoggingOptions$Builder.build(LoggingOptions.java:96) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at com.google.cloud.logging.LoggingOptions.getDefaultInstance(LoggingOptions.java:55) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at filters.LoggingFilter.liftedTree1$1(LoggingFilter.scala:19) ~[na:na]

Then I tried just removing excludeAll for "com.google.cloud" % "google-cloud-logging" % "1.37.1" and it worked.

I have tried to remove excludeAll from as many dependencies as possible and found that it still worked like this:

// Exclusion rules
val exclusionRules = Seq(
  ExclusionRule("io.grpc", "grpc-okhttp"),
  ExclusionRule("io.grpc", "grpc-netty"),
  ExclusionRule( "io.grpc", "grpc-core")
)

libraryDependencies ++= Seq(
  "com.google.cloud" % "google-cloud-core" % "1.37.1",
  jdbc,
  cache,
  ws,
  evolutions,
  "mysql" % "mysql-connector-java" % "5.1.28",
  "com.google.cloud.sql" % "mysql-socket-factory" % "1.0.2",
  "com.roundeights" %% "hasher" % "1.2.0",
  "io.intercom" % "intercom-java" % "2.3.3",
  "com.mixpanel" % "mixpanel-java" % "1.4.2",
  "eu.inn" %% "fluentd-scala" % "0.1.13",
  "com.typesafe.play" %% "anorm" % "2.4.0",
  "com.google.firebase" % "firebase-admin" % "4.0.3",
  "org.specs2" %% "specs2-core" % "3.6.2" % "test",
  "us.raudi.pushraven" % "Pushraven" % "1.0.2",
  "com.google.cloud" % "google-cloud-speech" % "0.20.1-alpha" excludeAll(exclusionRules:_*),
  "com.google.auth" % "google-auth-library-oauth2-http" % "0.6.0",
  "com.google.cloud" % "google-cloud-logging" % "1.37.1",
  "com.google.guava" % "guava" % "25.1-jre",
  "com.github.rishabh9" %% "mdc-propagation-dispatcher" % "0.0.5",
  "com.github.nscala-time" %% "nscala-time" % "2.18.0",
  "com.google.cloud" % "google-cloud-datastore" % "1.14.0" excludeAll(exclusionRules:_*),
  "com.github.davidmoten" % "geo" % "0.7.1",
  "com.danielasfregola" %% "twitter4s" % "3.0",
  "com.google.cloud" % "google-cloud-pubsub" % "1.37.1"
)

but removing excludeAll from google-cloud-speech or google-cloud-datastore results in an error. Removing from google-cloud-speech results in:

Caused by: java.lang.AbstractMethodError: io.grpc.netty.NettyChannelBuilder$NettyTransportFactory.getScheduledExecutorService()Ljava/util/concurrent/ScheduledExecutorService;
    at io.grpc.internal.CallCredentialsApplyingTransportFactory.getScheduledExecutorService(CallCredentialsApplyingTransportFactory.java:54) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:576) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:410) ~[grpc-core-1.13.1.jar:1.13.1]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:206) ~[gax-grpc-1.29.0.jar:1.29.0]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:157) ~[gax-grpc-1.29.0.jar:1.29.0]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:149) ~[gax-grpc-1.29.0.jar:1.29.0]
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:151) ~[gax-1.29.0.jar:1.29.0]
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:116) ~[gax-1.29.0.jar:1.29.0]
    at com.google.cloud.logging.spi.v2.GrpcLoggingRpc.<init>(GrpcLoggingRpc.java:127) ~[google-cloud-logging-1.37.1.jar:1.37.1]
    at com.google.cloud.logging.LoggingOptions$DefaultLoggingRpcFactory.create(LoggingOptions.java:64) ~[google-cloud-logging-1.37.1.jar:1.37.1]

while removing from google-cloud-datastore results in:

Caused by: java.lang.NoSuchMethodError: io.grpc.okhttp.OkHttpChannelProvider.isAndroid()Z
    at io.grpc.okhttp.OkHttpChannelProvider.priority(OkHttpChannelProvider.java:47) ~[grpc-okhttp-1.0.1.jar:1.0.1]
    at io.grpc.ManagedChannelProvider$1.getPriority(ManagedChannelProvider.java:49) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.ManagedChannelProvider$1.getPriority(ManagedChannelProvider.java:41) ~[grpc-core-1.13.1.jar:1.13.1]
    at io.grpc.ServiceProviders$1.compare(ServiceProviders.java:78) ~[grpc-core-1.13.1.jar:1.13.1]
    at java.util.Collections$ReverseComparator2.compare(Collections.java:5178) ~[na:1.8.0_131]
    at java.util.TimSort.countRunAndMakeAscending(TimSort.java:360) ~[na:1.8.0_131]
    at java.util.TimSort.sort(TimSort.java:220) ~[na:1.8.0_131]
    at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_131]
    at java.util.ArrayList.sort(ArrayList.java:1454) ~[na:1.8.0_131]
    at java.util.Collections.sort(Collections.java:175) ~[na:1.8.0_131]

Any downsides expected from these excludeAll rules? What would be the ideal solution here?

I can't think of any downsides if your application is working as expected. The problem is that different libraries here are using different versions of these dependencies. For example, if you use sbt-assembly (depending on the MergeStrategy) only one of them gets picked up in your build.

I see. So in this case, since excludeAll is applied to google-cloud-speech and google-cloud-datastore a failure would be expected in one of those if these libraries would be incompatible by a dependency version chosen by other libraries, right?

This is likely caused by incompatible dependencies between your versions of google-cloud-speech and google-cloud-datastore.

We advise importing google-cloud-bom for dependency management as it will help ensure you are using compatible artifacts provided by google-cloud-java

if your running with maven, run mvn install clean in your IDE terminal and see what happens. Had the same error and it worked for me when I ran that command.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bric3 picture bric3  路  3Comments

raintears picture raintears  路  3Comments

Electricks94 picture Electricks94  路  4Comments

lucmult picture lucmult  路  5Comments

Mistic92 picture Mistic92  路  5Comments