Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Add support for Kotlin Coroutines #409

Closed
jamesward opened this issue Dec 14, 2020 · 4 comments
Closed

Add support for Kotlin Coroutines #409

jamesward opened this issue Dec 14, 2020 · 4 comments
Assignees
Labels
type: compatibility Native image compatibility issue
Milestone

Comments

@jamesward
Copy link

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"
	}
@jamesward
Copy link
Author

Here is a project that reproduces the error (graalvm branch):
https://github.com/jamesward/springboot-kotlin-reactive-demo/tree/graalvm

@sdeleuze sdeleuze added this to the 0.8.5 milestone Dec 15, 2020
@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 18, 2020

If have switch KotlinDetector initialization to build time and order to fix that, then added Continuation related 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:

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.

@sdeleuze sdeleuze modified the milestones: 0.8.5, 0.9.1, 0.9.x backlog Dec 18, 2020
@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 18, 2020

For the time being, I have documented that Coroutines are not supported yet.

@sdeleuze sdeleuze added the type: compatibility Native image compatibility issue label Jan 8, 2021
@sdeleuze sdeleuze modified the milestones: 0.9.x backlog, 0.9.0 Feb 23, 2021
@sdeleuze sdeleuze added type: documentation A documentation task and removed type: compatibility Native image compatibility issue labels Feb 23, 2021
@sdeleuze sdeleuze changed the title Runtime Error with Kotlin Coroutines Document how to use Kotlin Coroutines Feb 23, 2021
@sdeleuze
Copy link
Contributor

sdeleuze commented 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 of webmvc-kotlin that uses WebFlux and Coroutines. Depends on #453.

@sdeleuze sdeleuze self-assigned this Feb 23, 2021
@sdeleuze sdeleuze changed the title Document how to use Kotlin Coroutines Add support for Kotlin Coroutines Feb 24, 2021
@sdeleuze sdeleuze added type: compatibility Native image compatibility issue and removed type: documentation A documentation task labels Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: compatibility Native image compatibility issue
Development

No branches or pull requests

2 participants