Skip to content

Caused by: java.lang.NoSuchFieldError: okhttp3/RequestBody.Companion #515

Description

@jacksierkstra

Expected Behavior

Being able to construct a DaprClient by using new DaprClientBuilder().build().

Actual Behavior

Instead of being able to construct a new instance, the application crashes with the following stacktrace:

Caused by: java.lang.NoSuchFieldError: okhttp3/RequestBody.Companion
	at io.dapr.client.DaprHttp.<clinit>(DaprHttp.java:108) ~[dapr-sdk-1.1.0-SNAPSHOT.jar:na]
	at io.dapr.client.DaprHttpBuilder.buildDaprHttp(DaprHttpBuilder.java:57) ~[dapr-sdk-1.1.0-SNAPSHOT.jar:na]
	at io.dapr.client.DaprHttpBuilder.build(DaprHttpBuilder.java:36) ~[dapr-sdk-1.1.0-SNAPSHOT.jar:na]
	at io.dapr.client.DaprClientBuilder.buildDaprClientHttp(DaprClientBuilder.java:160) ~[dapr-sdk-1.1.0-SNAPSHOT.jar:na]
	at io.dapr.client.DaprClientBuilder.buildDaprClient(DaprClientBuilder.java:127) ~[dapr-sdk-1.1.0-SNAPSHOT.jar:na]
	at io.dapr.client.DaprClientBuilder.build(DaprClientBuilder.java:107) ~[dapr-sdk-1.1.0-SNAPSHOT.jar:na]
	at com.dapr.backendservice.ApplicationConfiguration.daprClient(ApplicationConfiguration.java:13) ~[classes/:na]
	at com.dapr.backendservice.ApplicationConfiguration$$EnhancerBySpringCGLIB$$667a9fdc.CGLIB$daprClient$0(<generated>) ~[classes/:na]
	at com.dapr.backendservice.ApplicationConfiguration$$EnhancerBySpringCGLIB$$667a9fdc$$FastClassBySpringCGLIB$$86e422be.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.4.jar:5.3.4]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.4.jar:5.3.4]
	at com.dapr.backendservice.ApplicationConfiguration$$EnhancerBySpringCGLIB$$667a9fdc.daprClient(<generated>) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.4.jar:5.3.4]
	... 22 common frames omitted

Process finished with exit code 1

Steps to Reproduce the Problem

I created a very small Spring Boot application that creates a DaprClient upon starting up as a bean.

The application has the following (relevant) dependencies:

  <properties>
        <java.version>11</java.version>
        <dapr.version>1.1.0-SNAPSHOT</dapr.version>
    </properties>
<dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
          <groupId>io.dapr</groupId>
          <artifactId>dapr-sdk</artifactId>
          <version>${dapr.version}</version>
      </dependency>
      <dependency>
          <groupId>io.dapr</groupId>
          <artifactId>dapr-sdk-springboot</artifactId>
          <version>${dapr.version}</version>
      </dependency>
  </dependencies>

And I added the following configuration:

@Configuration
public class ApplicationConfiguration {

    @Bean
    public DaprClient daprClient() {
        return new DaprClientBuilder().build();
    }
}

When I start my application, it crashes. Tried with both dapr version 1.0.0 and 1.1.0-SNAPSHOT.

Release Note

RELEASE NOTE: FIX Bug in construction of HTTP client.

Activity

  1. artursouza commented on Mar 16, 2021

    @artursouza
    Contributor

    @jacksierkstra This is a common issue when the OkHTTP version conflicts from the Dapr SDK and any of your other dependencies. You can fix this by changing the springboot version to one that uses a compatible OkHTTP version or force a compatible okHTTP version in your project by adding the following dependency:

        <dependency>
          <groupId>com.squareup.okhttp3</groupId>
          <artifactId>okhttp</artifactId>
          <version>4.9.0</version>
        </dependency>
  2. added
    questionFurther information is requested
    and removed
    kind/bugSomething isn't working
    on Mar 16, 2021
  3. jacksierkstra commented on Mar 16, 2021

    @jacksierkstra
    Author

    Ok, thank you.

  4. added a commit that references this issue on Aug 29, 2021
  5. MotaOcimar commented on May 11, 2022

    @MotaOcimar

    I'm using Quarkus and get
    FINE Unable to find OkHttpChannelProvider: java.lang.ClassNotFoundException: io.grpc.okhttp.OkHttpChannelProvider

    I tried adding the okhttp dependency but the problem continues.

  6. denniszielke commented on Jun 9, 2022

    @denniszielke
    Member

    @MotaOcimar have you also added the quarkus grpc dependency? After that I was able to use the dapr sdk from Quarkus native image.

  7. MotaOcimar commented on Jun 22, 2022

    @MotaOcimar

    @MotaOcimar have you also added the quarkus grpc dependency? After that I was able to use the dapr sdk from Quarkus native image.

    I added the quarkus-grpc dependecy and the application don't even build due to Type io.quarkus.arc.deployment.RecorderBeanInitializedBuildItem not present.

    Then I added the quarkus-arc-deployment dependency and got

    A required class was missing while executing io.quarkus.platform:quarkus-maven-plugin:2.2.2.Final:build:
        io/quarkus/arc/AsyncObserverExceptionHandler
    

    So I tried to add the ArC Runtime and/or Quarkus ArC Runtime dependecies, but with no success.
    I don't really know the difference between these last two dependencies, but each one led me to a different error, as did adding the two.

  8. MotaOcimar commented on Jun 28, 2022

    @MotaOcimar

    I also tried the Quarkus Dapr Runtime but got java.lang.NoSuchFieldError: Companion

  9. thegovind commented on Jul 9, 2022

    @thegovind

    +1 as @MotaOcimar - Tried to add okhttp as described in #515 (comment) and the dependency, as well as quarkus-grpc, resulting the same error:

    Caused by: java.lang.NoSuchFieldError: Companion
            at io.dapr.client.DaprHttp.<clinit>(DaprHttp.java:129)
    
  10. thegovind commented on Jul 10, 2022

    @thegovind

    Resolved it with the following version combination:

    <dapr.version>1.5.0</dapr.version>
    <okhttp.version>4.10.0</okhttp.version>
    
  11. MotaOcimar commented on Jul 11, 2022

    @MotaOcimar

    Resolved it with the following version combination:

    <dapr.version>1.5.0</dapr.version>
    <okhttp.version>4.10.0</okhttp.version>
    

    It doesn't work for me 😢
    I continue with error Unable to find OkHttpChannelProvider: java.lang.ClassNotFoundException: io.grpc.okhttp.OkHttpChannelProvider

  12. MotaOcimar commented on Jan 12, 2023

    @MotaOcimar

    Is there any workaround for this problem?

    I'm also trying with Spring instead of Quarkus and I'm getting stuck with it 😭

    Tried different combinations of versions but no luck

  13. MotaOcimar commented on Jan 12, 2023

    @MotaOcimar

    With Dapr version 1.7.1 and okhttp version 4.9.0 I get

    java.lang.NoClassDefFoundError: Could not initialize class io.dapr.client.DaprHttp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions