After upgrading to Spring Boot 3.2.4 we noticed ClassCastException and NullPointerException in org.springframework.core.CoroutinesUtils.lambda$invokeSuspendingFunction

# testSuspendFunctionAsMethodParam
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.JvmClassMappingKt.getJavaClass, parameter <this>

    at kotlin.jvm.JvmClassMappingKt.getJavaClass(JvmClassMapping.kt)
    at org.springframework.core.CoroutinesUtils.lambda$invokeSuspendingFunction$2(CoroutinesUtils.java:131)
    at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4.invokeSuspend(IntrinsicsJvm.kt:270)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)

# testOpenMethodInSuperClass
java.lang.ClassCastException: class kotlin.reflect.jvm.internal.KTypeParameterImpl cannot be cast to class kotlin.reflect.KClass (kotlin.reflect.jvm.internal.KTypeParameterImpl and kotlin.reflect.KClass are in unnamed module of loader 'app')
    at org.springframework.core.CoroutinesUtils.lambda$invokeSuspendingFunction$2(CoroutinesUtils.java:130)
    at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4.invokeSuspend(IntrinsicsJvm.kt:270)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)

Here is a little sample project to reproduce it: https://github.com/sebastianfuss/spring-coroutine-invocation-test

Comment From: snicoll

Thanks for the report but Spring Boot 3.4.2 does not exist. Did you mean 3.2.4?

Here is a little test to reproduce it:

Please don't share code in text as it means we'll have to copy paste that in a project to attempt to reproduce what you experienced and that alone isn't enough for us to do so. Please share a small sample we can use to reproduce the issue. You can attach a zip here or push the code to a GitHub repository.

Comment From: sebastianfuss

Hi @snicoll Yeah. I fixed the mistake in the spring boot version and linked a little sample project. Hope that helps. Thanks in advance! Have a nice day!

Comment From: jhoeller

This looks related to #32510 where that hard KClass cast got revised for 6.1.6 already. Could you try a recent 6.1.6 snapshot and see whether your scenario works again as well?

Comment From: sebastianfuss

👍 It's solved with the recent 6.1.6 snapshot. Thanks!