Skip to content

Generic Kotlin controllers got broken in 6.1.5 #32510

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

Closed
utikeev opened this issue Mar 21, 2024 · 0 comments
Closed

Generic Kotlin controllers got broken in 6.1.5 #32510

utikeev opened this issue Mar 21, 2024 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression
Milestone

Comments

@utikeev
Copy link

utikeev commented Mar 21, 2024

Affects: 6.1.5

Generic controllers written in Kotlin stopped working after the upgrade to 6.1.5 from 6.1.4 with:

Caused by: 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')
       org.springframework.web.method.support.InvocableHandlerMethod$KotlinDelegate.invokeFunction(InvocableHandlerMethod.java:321)
       org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:252)
       org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:188)
       org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)
       org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:925)

It seems that the issue was introduced in c1d4b61 when the check for instanceof KClass<?> has been removed. KType.classifier returns KTypeParameter for the generic arguments of controller methods and the cast fails.

Here is the reproduction example: https://github.com/utikeev/spring-generic-controller-6.1.5-issue
One can check that with Spring Boot 3.2.3 SpringGenericControllerApplicationTests passes successfully, while with the Spring Boot 3.2.4 the test fails with the aforementioned error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants