encountering an odd error trying out porting an ex...
# ktor
p
encountering an odd error trying out porting an existing working application (1.6.8) to ktor 2.0.1:
Copy code
java.lang.UnsupportedOperationException: This class is an internal synthetic class generated by the Kotlin compiler, such as an anonymous class for a lambda, a SAM wrapper, a callable reference, etc. It's not a Kotlin class or interface, so the reflection library has no idea what declarations it has. Please use Java reflection to inspect this class: class com.xxx.SessionManagementKt$swapUserSession$1$1
 	at kotlin.reflect.jvm.internal.KClassImpl.reportUnresolvedClass(KClassImpl.kt:316)
 	at kotlin.reflect.jvm.internal.KClassImpl.access$reportUnresolvedClass(KClassImpl.kt:44)
...
 	at kotlin.jvm.internal.CallableReference.getTypeParameters(CallableReference.java:156)
	at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.typeParameter(ReflectionFactoryImpl.java:134)
 	at kotlin.jvm.internal.Reflection.typeParameter(Reflection.java:174)
 	at com.xxx.SessionManagement$swapUserSession$1$1.invokeSuspend(SessionManagement.kt:162)
 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
 	at arrow.continuations.generic.SuspendMonadContinuation.resumeWith(SuspendingComputation.kt:54)
 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
 	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
 	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
 	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503)
 	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
 	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
 	at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda-1$lambda-0(NettyApplicationEngine.kt:260)
it appears to be happening inside a route:
Copy code
fun <A, B, C>Route.swapUserSession(...) {
    authenticate("auth-basic") {
        post("/internal/session") {
            ...
            doThing() 
        }
    } 
}

suspend fun <A, B, C>doThing(): Bla<A>
using kotlin 1.6.21
the suspend fun is a top level function and has generic parameters, so does the function that creates the route
i'm not sure why reflection is (now?) involved here
the invocation to
doThing()
actually succeeds and returns a value
@Aleksei Tirman [JB] any idea by any chance?
a
Sorry for the long delay with a replay. Unfortunately, I cannot reproduce it with the following code:
Copy code
fun main() {
    embeddedServer(Netty, port = 3333) {
        install(Authentication) {
            basic("auth-basic") {
                validate {
                    UserIdPrincipal("123")
                }
            }
        }
        routing {
            swapUserSession<Int, Int, Int>()
        }
    }.start(wait = true)
}

fun <A, B, C> Route.swapUserSession() {
    authenticate("auth-basic") {
        post("/") {
            //...
            doThing<A,B,C>()
        }
    }
}

suspend fun <A, B, C>doThing(): Bla<A> {
    return Bla<Int>() as Bla<A>
}

class Bla<T> {

}