-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Unable to use kotlin value classes as function arguments to functions mapping web endpoints #31698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, I wanted to mention that I am experiencing the same issue, even though I am not directly using the value class in the controller path variable. If I invoke any bean methods with a value class in the parameters, the outcome remains the same: I receive the error message We are currently utilizing Java 21 on our end. Thanks |
It looks like Kotlin reflection does not support |
Confirmed to be a Kotlin bug, you can follow the resolution of https://youtrack.jetbrains.com/issue/KT-64097. |
While not an ideal solution, one possible workaround for the Kotlin A simpler mitigation might be to fallback on the java reflection code path if Edit: Just to clarify. We upgraded from 6.0.13, where it worked fine. |
Based on latest Kotlin team feedback, we may have to handle that on Spring side (in a way close to what you suggested @junkdog). See sdeleuze@gh-31698 draft commit. |
Similar to spring-projectsgh-31698 but for Coroutines. See spring-projectsgh-31846
Since spring-boot 3.2.1, we have noticed a significant performance drop in our application. Could you please take a look at this? Thanks 🙇 |
Could you please share an indication of the impact you see, for example % of drop of the throughput observed for example, with how much parameters are used. |
This is a very simple Kotlin-based controller method that makes it easy to test. @GetMapping("/message")
fun message(message1: String, message2: String, message3: String): String {
return "$message1 $message2 $message3"
} benchmark
async-profilerLet me know if you need more information. 😄 |
@koo-taejin I confirm a significant slowdown with my own tests, could you please create a new dedicated related issue, reusing the informations you shared above? |
This commit fixes a performance regression caused by spring-projectsgh-31698, and more specifically by KClass#isValue invocations which are slow since they load the whole module to find the class to get the descriptor. After discussing with the Kotlin team, it has been decided that only checking for the presence of `@JvmInline` annotation is enough for Spring use case. As a consequence, this commit introduces a new KotlinDetector#isInlineClass method that performs such check, and BeanUtils, CoroutinesUtils and WebMVC/WebFlux InvocableHandlerMethod have been refined to leverage it. Closes spring-projectsgh-32334
I've encountered a bug in Spring Framework version 6.1.0 related to Kotlin value classes in web endpoints. The issue arises when a Kotlin
value class
is used as a path variable in a Spring Boot controller. This results in a failure to correctly handle the value type, causing runtime exceptions.Environment
Spring Framework Version: 6.1.0 (with spring-boot 3.2.0)
Kotlin Version: 1.9.20
JVM Version: 17
Steps to reproduce
Expected behavior
Both endpoints should accept their respective path variables without any issue
Actual Behavior
The endpoint with the Kotlin value class as a path variable fails at runtime with the error message "object is not an instance of declaring class".
Minimal example
The text was updated successfully, but these errors were encountered: