You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is a Kotlin class with multiple constructors that all have default values, there might occur a bug since the latest release (it used to work in Spring Boot 3.1.6, but does not in Spring 3.2.2).
Kotlin generates two synthetic constructors with the same parameter count. Hence, Spring Data compares detected constructors with synthetic constructors that may have different types, leading to the error java.lang.IllegalArgumentException: Class declares 2 type parameters, but 0 were provided.
Problem
In my oppinion, the problem is in the class org.springframework.data.mapping.model.KotlinInstantiationDelegate, line 212:
if ((detectedConstructor.getParameterCount() + syntheticParameters) != candidate.getParameterCount())
This line skips the comparison between the detected and the candidate constructor, if the parameter count is not equal. In my example, this does not prevent the comparison of ObjectId and Map<String,String>, which then leads to the described error when calling Reflection.typeOf(kotlinClass) for the map without generics.
The text was updated successfully, but these errors were encountered:
Thank you @huberchrigu. As yo mentioned the issue stems from the attempt to look up constructor parameter types that have their generic type signature erased. We're investigating if we can fill up missing args with KTypeProjection.star when calling Reflection.typeOf.
We now fill up missing KTypeProjection arguments with star because the Kotlin Reflection.typeOf resolution fails if arguments are not provided.
Closes#3041
Original pull request: #3048
Tiny naming tweaks.
See #3041
Original pull request: #3048
mp911de
changed the title
Spring Data Mapping fails on multiple synthetic Kotlin constructors with same argument count
Kotlin constructor detection fails during KType derivation
Feb 21, 2024
When there is a Kotlin class with multiple constructors that all have default values, there might occur a bug since the latest release (it used to work in Spring Boot 3.1.6, but does not in Spring 3.2.2).
Example
Repository: https://github.com/huberchrigu/spring-data-kotlin-test
I have a MongoDB document
Kotlin generates two synthetic constructors with the same parameter count. Hence, Spring Data compares detected constructors with synthetic constructors that may have different types, leading to the error java.lang.IllegalArgumentException: Class declares 2 type parameters, but 0 were provided.
Problem
In my oppinion, the problem is in the class
org.springframework.data.mapping.model.KotlinInstantiationDelegate
, line 212:This line skips the comparison between the detected and the candidate constructor, if the parameter count is not equal. In my example, this does not prevent the comparison of
ObjectId
andMap<String,String>
, which then leads to the described error when callingReflection.typeOf(kotlinClass)
for the map without generics.The text was updated successfully, but these errors were encountered: