question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MotaOcimarcommented, Jun 28, 2022

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

0reactions
MotaOcimarcommented, Jul 11, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoSuchFieldError: Companion when using okhttp3 ...
Yeah, the problem is that selenium-remote-driver:3.141.59 still uses okhttp:3.11.0 . I changed my dependency to that version and the error is ...
Read more >
Eclipse Okhttp Error Java.Lang.Nosuchfielderror: Companion
I cant even work with blank Kotlin project.Attached image shows how it looks like.Can. When Spring on CP: OkHttpKt.requestBody java.lang.NoSuchFieldError: ...
Read more >
Hi got an issue that I can t figure out I made a lib based o | Http4k
Companion java.lang.NoSuchFieldError: Companion at org.http4k.client.OkHttpKt.requestBody(OkHttp.kt:75) at org.http4k.client.OkHttpKt.asOkHttp(OkHttp.kt:68) ...
Read more >
Upgrading to OkHttp 4 - Square Open Source
OkHttp 4.x upgrades our implementation language from Java to Kotlin and keeps ... Depending on code in this package is bad and will...
Read more >
java lang ClassNotFoundException okhttp3 ConnectionPool
Below is my simple Selenium Test Code: public static void main(String[] args) ... Caused by: java.lang.ClassNotFoundException: okhttp3.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found