Skip to content

Generic Kotlin controllers got broken in 6.1.5 #32510

Closed
@utikeev

Description

@utikeev

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.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)theme: kotlinAn issue related to Kotlin supporttype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions