-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Thanks in advance for reading this issue. After thorough search in StackOverflow.com, I found nothing about this in there(for every combinations of keywords: Spring, Kotlin extension, @Validated ArrayIndexOutOfBoundsException). There is a workaround hopefully, but it would be great if this issue is solved as well!
While I was writing a Kotlin Mixin, I bumped into an ArrayIndexOutOfBoundsException caused by CGLIB proxied class. Spent around 30 minutes and found that this is because of a peculiar combination such as:
- declare an Kotlin extension function that receiver type is using Java/Kotlin generics(MultiValueMap<String, String> is in this case)
interface FetchCriteriaRequestMixin {
fun <SORT> MultiValueMap<String, String>.toFetchCriteria(
sortByProvider: (sortBy: String?) -> SORT,
defaultSortDirection: SortDirection,
defaultPage: Int,
defaultFetchSizeRange: IntRange
): ContentsFetchCriteria<SORT>
}
- let this method is exposed to
org.springframework.validation.annotation.Validatedannotated class which is to be a proxy target
@Validated
interface GetRepliesController
@RestController
internal class GetRepliesControllerImpl : GetRepliesController, FetchCriteriaRequestMixin
- declare a spring-data-jpa dependency with Hibernate
Yet I couldn't found any solution for this, but there is a workaround which are 1. eliminate an extension function and make it as like plain Java utility method, 2. eliminate generics in receiver type of extension function.
I'm leaving my Github source code link for better bug reproduction.
Mixin type - an original cause of this issue
@Validated @RestController that utilises this mixin
Tested under:
- org.springframework.boot:spring-boot-starter:2.3.1.RELEASE (depends on Spring 5.2.7.RELEASE)
- javax.validation:validation-api:2.0.1.Final
- jakarta.servlet:jakarta.servlet-api:4.0.3
- org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72
- org.jetbrains.kotlin:kotlin-allopen:1.3.72