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.

OkHttp 4.x okhttp3.internal.Util class loading issues when using AppCDS

See original GitHub issue

Hi,

We’ve recently upgraded to OkHttp 4.x (from 3.x) and saw that Java applications that use AppCDS archives, where the okhttp3.internal.Util class is included, fail to start. The error is:

java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    okhttp3/internal/Util
  Reason:
    Type '[Ljava/lang/Object;' is not assignable to 'okhttp3/internal/Util'

	at okhttp3.OkHttpClient.<clinit>(OkHttpClient.kt:1073)

Looking at the classes loaded, it looks like all of them are loaded from the shared objects file

[0.215s][info][class,load] okhttp3.internal.Util source: shared objects file
[0.284s][info][class,load] okhttp3.Call$Factory source: shared objects file
[0.284s][info][class,load] okhttp3.WebSocket$Factory source: shared objects file
[0.284s][info][class,load] okhttp3.OkHttpClient source: shared objects file
[0.285s][info][class,load] okhttp3.OkHttpClient$Companion source: shared objects file
[0.287s][info][class,load] okhttp3.Protocol source: shared objects file
[0.287s][info][class,load] okhttp3.Protocol$Companion source: shared objects file

Steps to reproduce

I’ve managed to isolate this to a very simple Docker image contained in the attachment okhttp_appcds.zip. To replicate, run:

docker build -t okhttp_appcds . && docker run --rm okhttp_appcds

I’ll also include the Java code, Gradle build and the Dockerfile for clarity:

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class TestOkHttpAppCDS {

    public static void main(String[] args) throws Exception {
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder().url("http://example.com").build();

        try (Response response = client.newCall(request).execute()) {
            System.out.printf("RESPONSE: \n%s\n", response.body().string());
        }
        
        System.exit(0);
    }
}
plugins {
    id 'java'
}

compileJava {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

jar {
    manifest {
        attributes 'Main-Class': 'TestOkHttpAppCDS'
    }

    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile "com.squareup.okhttp3:okhttp:4.8.1"
}
FROM gradle:jdk11

COPY src src
COPY build.gradle .

RUN gradle build

RUN java -XX:DumpLoadedClassList=classes.lst -jar build/libs/gradle.jar

# Uncomment this to remove oktthp from the CDS archive
# RUN sh -c 'cat classes.lst | grep -v ^okhttp3 > classes.lst' 

RUN java -Xshare:dump -XX:SharedClassListFile=classes.lst -XX:SharedArchiveFile=app-cds.jsa -jar build/libs/gradle.jar

CMD java -XX:+UseAppCDS -Xshare:on -XX:SharedArchiveFile=app-cds.jsa -Xlog:class+load -jar build/libs/gradle.jar

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

3reactions
danielgblancocommented, Jan 4, 2021

Hi @norbertas-gaulia, we ended up filtering our oktthp3 classes out of the CDS archive as mentioned in the Dockerfile above (uncommenting the bits that need uncommenting).

1reaction
iklamcommented, May 6, 2022

A bug has been filed for the JDK: https://bugs.openjdk.java.net/browse/JDK-8286277

Read more comments on GitHub >

github_iconTop Results From Across the Web

3.x Change Log - OkHttp
Fix : Don't crash looking up an absent class on certain buggy Android 4.x devices. ... New: Automatic module name of okhttp3 for...
Read more >
Error building a request and initializing client for OkHttp3 on ...
It looks like you have an issue with the dependency and/or JVM. The java.lang.BootstrapMethodError may mean there is something work with the ...
Read more >
How To Disable Okhttp3.Internal.Platform.Platform Log From ...
I am using okhttp3 to make requests to the server not using retrofit. quite a few questions about it but I can not...
Read more >
Application / Dynamic Class Data Sharing In HotSpot JVM
These classes (around 1400 in total, as of JDK 17) are loaded by the ... Launching the JVM with a different GC, SerialGC...
Read more >
4 Class Data Sharing - Java - Oracle Help Center
This chapter describes the class data sharing (CDS) feature that can help reduce the startup time and memory footprints for Java applications.
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