Skip to content

Binary incompatibility with ktor-io 2.x results in NoSuchMethodError exceptions at runtime #480

@AlexandreBrown

Description

@AlexandreBrown

Describe the bug

When using response.body?.toByteArray(), I get the following errors :

23:47:40.748 [DefaultDispatcher-worker-5] DEBUG httpTraceMiddleware - service: S3; operation: GetObject; - HttpResponse: 200: OK
23:47:40.767 [DefaultDispatcher-worker-5] ERROR ktor.application - Websocket handler failed
java.lang.NoSuchMethodError: 'void io.ktor.utils.io.bits.Memory.copyTo-iAfECsU(java.nio.ByteBuffer, java.nio.ByteBuffer, long, long, long)'
	at aws.smithy.kotlin.runtime.io.SdkByteBufferKt.readFully-aPcrCvc(SdkByteBuffer.kt:377)
	at aws.sdk.kotlin.runtime.http.engine.crt.SegmentKt.copyTo(Segment.kt:21)
	at aws.sdk.kotlin.runtime.http.engine.crt.AbstractBufferedReadChannel.readAsMuchAsPossible(AbstractBufferedReadChannel.kt:113)
	at aws.sdk.kotlin.runtime.http.engine.crt.AbstractBufferedReadChannel.readRemaining$suspendImpl(AbstractBufferedReadChannel.kt:97)
	at aws.sdk.kotlin.runtime.http.engine.crt.AbstractBufferedReadChannel.readRemaining(AbstractBufferedReadChannel.kt)
	at aws.smithy.kotlin.runtime.io.SdkByteReadChannel$DefaultImpls.readRemaining$default(SdkByteReadChannelJVM.kt:35)
	at aws.smithy.kotlin.runtime.content.ByteStreamKt.consumeStream(ByteStream.kt:67)
	at aws.smithy.kotlin.runtime.content.ByteStreamKt.toByteArray(ByteStream.kt:83)

Expected behavior

We are able to read the response body.

Current behavior

Trying to read the response body throws an exception java.lang.NoSuchMethodError

Steps to Reproduce

Here is the code to reproduce (taken from the doc pretty much as-is)

import aws.sdk.kotlin.services.s3.S3Client
import aws.sdk.kotlin.services.s3.model.GetObjectRequest
import aws.smithy.kotlin.runtime.content.toByteArray  
import kotlinx.coroutines.async

private fun downloadImageFromS3(imageLocation: String) =
    async {
        val request = createS3GetObjectRequest(imageLocation)
	var imageBytes: ByteArray? = null

	S3Client(s3Configuration).use { s3 ->
		s3.getObject(request) { response ->
			imageBytes = response.body?.toByteArray()
		}
	}

	imageBytes
}

private fun createS3GetObjectRequest(imageLocation: String) =
	GetObjectRequest {
		key = imageLocation
		bucket = s3BucketName
	}

Possible Solution

No response

Context

I am running Ktor 2.0.0-beta-1.
The error still occurs after deleting all the libraries downloaded, deleting gradle cache then re-downloading them via gradle sync.
Here is a screenshot of the dependencies that the S3 lib downloaded
image

AWS Kotlin SDK version used

0.9.5-beta

Platform (JVM/JS/Native)

JVM 11

Operating System and version

Ubuntu 20.04.3 LTS

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions