https://kotlinlang.org logo
#ktor
Title
# ktor
с

Стефан Јовановић

03/02/2022, 11:44 AM
I've received this error:
java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;
After trying to make a request to this endpoint:
Copy code
post("/home") {
    call.sessions.set(UserSession(id = "123", name = "Name"))
    call.respondRedirect(Endpoint.Authorized.path)
}
I'm using 2.0.0-beta-1 version.
e

e5l

03/02/2022, 11:45 AM
Hey, could you tell me the version you’re using?
с

Стефан Јовановић

03/02/2022, 11:46 AM
Copy code
2.0.0-beta-1
That 'call.sessions.set()' is creating this error. Even though I've setup a Session and Authentication plugin successfully.
e

e5l

03/02/2022, 11:47 AM
And could you also tell me what version you’re using?
с

Стефан Јовановић

03/02/2022, 11:48 AM
@e5l 2.0.0-beta-1
h

hfhbd

03/02/2022, 11:53 AM
I guess, Leonid means JDK version too, because java.nio.ByteBuffer is a JVM method
с

Стефан Јовановић

03/02/2022, 11:56 AM
Screenshot_1.png
h

hfhbd

03/02/2022, 12:12 PM
Which engine? But that's strange, java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; aka java.nio.Buffer.position(I)Ljava/nio/Buffer is available since Java 1.4.
с

Стефан Јовановић

03/02/2022, 12:17 PM
Netty, engine main
I had the same project but only with a different Ktor version (1.6.7) and everything seems to work just fine.
@e5l @hfhbd When I try to downgrade Ktor version from 2.0.0-beta-1 to 1.6.7 in my gradle.properties file, I'm getting this error when running the server. How I'm supposed to downgrade the Ktor version then? The question may sound stupid, but I'm really not sure how to do that...
j

jw

03/02/2022, 1:48 PM
In Java 9 the return type of various methods on ByteBuffer was changed to be covariant
So if you are compiling with JDK 9+ but running on 8 you'll see that exception, even with source compatibility set. You need to set the release flag which changes the bootclasspath (the built in APIs) to the old signature if you plan on running on an older JDK than you compile with.
h

hfhbd

03/02/2022, 1:51 PM
Or Ktor needs to be build with Java 8?
j

jw

03/02/2022, 1:51 PM
There were a bunch of articles written a few years ago about it. Here's the first one I found searching: https://saker.build/blog/javac_source_target_parameters/index.html but there's many more. I vaguely remember one from maybe Stuart Marks from Oracle too
No you never need to build with an old JDK
h

hfhbd

03/02/2022, 1:52 PM
And even this "simple" function (position(Int) is affected, because it returns ByteBuffer to allow chaining?
j

jw

03/02/2022, 1:53 PM
Yes
h

hfhbd

03/02/2022, 1:53 PM
Thanks!
с

Стефан Јовановић

03/02/2022, 2:08 PM
I've just upgraded to a version 11, and it works. Thanks guys 👍
158 Views