java.lang.NoSuchMethodError: okhttp3.internal.Platform.log AND Exception in thread "Okhttp Dispatcher" java.lang.NoSuchFieldError: INSTANCE

Viewed 2213

Help me, please. I have okhttp3 and logging-interceptor 4.7.2 versions. I have java.lang.NoSuchMethodError: okhttp3.internal.Platform.log in "Okhttp Dispatcher" thread when I call ONVIF getDeviceInformation. If I set okhttp3 3.14.7 version I have java.lang.NoSuchFieldError: INSTANCE in "Okhttp Dispatcher" thread.

<modelVersion>4.0.0</modelVersion>

<groupId>prj.group.id</groupId>
<artifactId>art.id</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.M4</version>
</parent>

<properties>
    <java-version>1.8</java-version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>5.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
        <version>5.2.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacv</artifactId>
        <version>1.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>ffmpeg</artifactId>
        <version>4.2.1-1.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>ffmpeg-platform</artifactId>
        <version>4.2.1-1.5.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.12</version>
    </dependency>
    <dependency>
        <groupId>be.teletask.onvif</groupId>
        <artifactId>onvif</artifactId>
        <version>1.0.2</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.7.2</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>4.7.2</version>
        </dependency>
        <dependency>
            <groupId>com.burgstaller</groupId>
            <artifactId>okhttp-digest</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.2.2.RELEASE</version>
        </plugin>
    </plugins>
</build>

<repositories>
    ***

</repositories>

<pluginRepositories>
    ***
</pluginRepositories>

Error in onError method when I call getDeviceInformation

OnvifManager manager = new OnvifManager();
manager.setOnvifResponseListener( new OnvifResponseListener() {
@Override
public void onError(OnvifDevice device, int I, String s) {
System.out.println(s);
}
...
});
...
manager.getDeviceInformation(onvifDevice, (device, information) -> {
// Don't reach this code
information.getModel();
});
2 Answers

I have okhttp3 and logging-interceptor 4.7.2 versions. I have java.lang.NoSuchMethodError: okhttp3.internal.Platform.log

It is a Dependency issue, You are using :

  1. okhttp-4.7.2
  2. logging-interceptor-4.7.2
  3. okhttp-digest-2.0

And Runtime dependency of okhttp-digest-2.0 is okhttp-4.0.1

Maven Repo: https://mvnrepository.com/artifact/com.burgstaller/okhttp-digest/2.0

So now you have two different versions of same library

1.okhttp-4.0.1 from okhttp-digest-2.0

2.okhttp-4.7.2

There was a change in log function(Which is what error is saying NoSuchMethodError:okhttp3.internal.Platform.log) we can see in the image

Log Function change between version 4.0.1 and 4.7.2

Solutions:

  1. You Can Update version of okhttp-digest which can work with okhttp-4.7.2
  2. You could exclude the okhttp dependency from okhttl-digest if you're not using the features relying on it.

As of 26th October 2020, latest okhttp-digest v2.5 requires okhttp v4.7.2 dependencies.

For future version of okhttp-digest, make sure to check equivalent okhttp dependencies.

Related