You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
I have a basic Kotlin coroutine controller method:
@GetMapping("/")
suspend fun index() = run {
"aasdf"
}
Works fine in the JVM but fails at runtime when using a native image (org.springframework.experimental:spring-graalvm-native:0.8.4):
java.lang.IllegalStateException: No primary or single public constructor found for interface kotlin.coroutines.Continuation - and no default constructor found either
at org.springframework.beans.BeanUtils.getResolvableConstructor(BeanUtils.java:250) ~[na:na]
Without the suspend it works as expected:
@GetMapping("/")
fun index(): String {
return "asdf"
}
The error I get, maybe resolvable with deeper work, is:
java.lang.IllegalArgumentException: Callable expects 2 arguments, but 1 were provided.
at kotlin.reflect.jvm.internal.calls.Caller$DefaultImpls.checkArguments(Caller.kt:20) ~[na:na]
I suspect kotlin-reflect to be too reflection based and big to be really a good fit for native, so in parrallel on working on that I have created spring-projects/spring-framework#21546 which would be an ambitious but IMO promising way to solve that.
We should be able to use Coroutines with proper documentation (add required entries with @NativeHint) until KT-44594 fix is available in Kotlin 1.5-M2. To be check with a modified version of webmvc-kotlin that uses WebFlux and Coroutines. Depends on #453.
Activity
jamesward commentedon Dec 15, 2020
Here is a project that reproduces the error (
graalvmbranch):https://github.com/jamesward/springboot-kotlin-reactive-demo/tree/graalvm
sdeleuze commentedon Dec 18, 2020
If have switch
KotlinDetectorinitialization to build time and order to fix that, then addedContinuationrelated reflection entries but that seems not sufficient, see https://github.com/spring-projects-experimental/spring-graalvm-native/tree/webflux-kotlin.The error I get, maybe resolvable with deeper work, is:
I suspect
kotlin-reflectto be too reflection based and big to be really a good fit for native, so in parrallel on working on that I have created spring-projects/spring-framework#21546 which would be an ambitious but IMO promising way to solve that.sdeleuze commentedon Dec 18, 2020
For the time being, I have documented that Coroutines are not supported yet.
[-]Runtime Error with Kotlin Coroutines[/-][+]Document how to use Kotlin Coroutines[/+]sdeleuze commentedon Feb 23, 2021
We should be able to use Coroutines with proper documentation (add required entries with
@NativeHint) until KT-44594 fix is available in Kotlin 1.5-M2. To be check with a modified version ofwebmvc-kotlinthat uses WebFlux and Coroutines. Depends on #453.[-]Document how to use Kotlin Coroutines[/-][+]Add support for Kotlin Coroutines[/+]