Skip to content
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

Generic Kotlin controllers got broken in 6.1.5 #32510

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 21, 2024
@snicoll snicoll added type: bug A general bug theme: kotlin An issue related to Kotlin support and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 21, 2024
@snicoll snicoll added this to the 6.1.6 milestone Mar 21, 2024
@sdeleuze sdeleuze self-assigned this Mar 21, 2024
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression and removed type: bug A general bug labels Mar 21, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 21, 2024
This commit reintroduce a more defensive parameter type check that skips
KClass casting for generic parameters.

Closes spring-projectsgh-32510
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