Skip to content

NoClassDefFoundError: okhttp3.ConnectionListener when using OkHttpEngine on JVM (okhttp3 5.1.0) #1641

@cj848

Description

@cj848

Describe the bug

Description

When constructing an S3Client (or any AWS SDK client) on the JVM using the default HTTP engine, the SDK attempts to wire in okhttp3.ConnectionListener. However, that class is not present in the version of OkHttp on the classpath, resulting in a NoClassDefFoundError during client initialization.

Expected Behavior

The S3Client (and other service clients) should initialize successfully and be ready to make HTTP calls using OkHttp without throwing any class load or linkage errors.

Actual Behavior

Client construction fails with: (see Current Behavior)

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected behavior

compatibility for okhttp 5.1.0

Current behavior

Caused by: java.lang.NoClassDefFoundError: okhttp3/ConnectionListener
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineKt.buildClientWithConnectionListener(OkHttpEngine.kt:167)
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineKt.access$buildClientWithConnectionListener(OkHttpEngine.kt:1)
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine.(OkHttpEngine.kt:49)
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine$Companion.invoke(OkHttpEngine.kt:42)
at aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngineJVMKt.newDefaultHttpEngine(DefaultHttpEngineJVM.kt:14)
at aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngineKt.DefaultHttpEngine(DefaultHttpEngine.kt:24)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineConstructor$1.invoke(HttpEngineConfigImpl.kt:20)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineConstructor$1.invoke(HttpEngineConfigImpl.kt:20)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl.engineSupplier$lambda$2(HttpEngineConfigImpl.kt:21)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl.buildHttpEngineConfig(HttpEngineConfigImpl.kt:77)
at aws.sdk.kotlin.services.s3.S3Client$Config$Builder.buildHttpEngineConfig(S3Client.kt)
at aws.sdk.kotlin.services.s3.S3Client$Config.(S3Client.kt:295)
at aws.sdk.kotlin.services.s3.S3Client$Config.(S3Client.kt)
at aws.sdk.kotlin.services.s3.S3Client$Config$Builder.build(S3Client.kt:542)
at aws.sdk.kotlin.services.s3.S3Client$Config$Builder.build(S3Client.kt:359)
at aws.smithy.kotlin.runtime.client.AbstractSdkClientBuilder.build(AbstractSdkClientBuilder.kt:20)
at aws.smithy.kotlin.runtime.client.AbstractSdkClientBuilder.build(AbstractSdkClientBuilder.kt:13)
at aws.smithy.kotlin.runtime.client.AbstractSdkClientFactory.invoke(AbstractSdkClientFactory.kt:22)
at app.config.S3ClientConfig.s3Client(S3ClientConfig.kt:29)
at app.config.S3ClientConfig$$SpringCGLIB$$0.CGLIB$s3Client$0()
at app.config.S3ClientConfig$$SpringCGLIB$$FastClass$$1.invoke()
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:400)
at app.S3ClientConfig$$SpringCGLIB$$0.s3Client()
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:171)
... 90 more
Caused by: java.lang.ClassNotFoundException: okhttp3.ConnectionListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
... 116 more

Steps to Reproduce

1.	Add AWS SDK for Kotlin and OkHttp dependencies(5.1.0) to your JVM project:
2.	In your Kotlin code, build an S3 client:
3.	Run the application.

Possible Solution

No response

Context

  1. Add AWS SDK for Kotlin and OkHttp dependencies to your JVM project, for example in Gradle:
  2. In your Kotlin code, build an S3 client: (okhttp 5.3.0)
  3. Run the application.

AWS SDK for Kotlin version

1.4.119

Platform (JVM/JS/Native)

JVM

Operating system and version

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue is a duplicate.third-partyThis issue is related to third-party libraries or applications.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions