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.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
aajtoddcommented, May 24, 2022

This will be available in the next release (0.16.0-beta) today or tomorrow hopefully.

3reactions
kapstahillarcommented, May 20, 2022

Please fix this soon, my application relies on it. I’m too far in on my project to revert back to last ktor version

Read more comments on GitHub >

github_iconTop Results From Across the Web

NoSuchMethodError io.ktor.utils.io.bits.Memory.copyTo-iAfECsU
Binary incompatibility 1.6.7 and 2.0.0-beta-1: NoSuchMethodError ... that having ktor-server-*:2.0.0-beta1 in the dependency set results in runtime errors:.
Read more >
Getting NoSuchMethodError at runtime - java - Stack Overflow
I just copied your code snippets with 2 different packages directly in to my netbean, compiled and runned C2. It did print the...
Read more >
WhatsNew 2.1 | Ktor Framework
Ktor client OutOfMemoryError while downloading large files ... CIO: A request through a proxy server results in 403 from Cloudflare.
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