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

Add support for Kotlin Coroutines #409

Closed

Description

@jamesward

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"
	}

Activity

  1. jamesward commented on Dec 15, 2020

    @jamesward
    Author

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

  2. added this to the 0.8.5 milestone on Dec 15, 2020
  3. sdeleuze commented on Dec 18, 2020

    @sdeleuze
    Contributor

    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.

  4. modified the milestones: 0.8.5, 0.9.1, on Dec 18, 2020
  5. sdeleuze commented on Dec 18, 2020

    @sdeleuze
    Contributor
  6. added
    type: compatibility
    on Jan 8, 2021
  7. modified the milestones: , 0.9.0 on Feb 23, 2021
  8. added
    type: documentation
    and removed
    type: compatibility
    on Feb 23, 2021
  9. changed the title [-]Runtime Error with Kotlin Coroutines[/-] [+]Document how to use Kotlin Coroutines[/+] on Feb 23, 2021
  10. sdeleuze commented on Feb 23, 2021

    @sdeleuze
    Contributor

    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.

  11. self-assigned this
    on Feb 23, 2021
  12. changed the title [-]Document how to use Kotlin Coroutines[/-] [+]Add support for Kotlin Coroutines[/+] on Feb 24, 2021
  13. added
    type: compatibility
    and removed
    type: documentation
    on Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: compatibility

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions