Kotlin extension function on parameterized type leads to ArrayIndexOutOfBoundsException during validateParameters

Description

Context

  • Method constraints validation

  • Kotlin

    • Presence of extension function on parameterized type within the validated object

Problem

Given the following code making use of method constraint validation

SimpleFooService.kt

Attempting to execute the code leads to ArrayIndexOutOfBoundsException and the given arguments not being validated:

Preliminary analysis

Debugging reveals that org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider#findExecutableMetaData is retrieving an incorrect JavaBeanExecutable result from JavaBeanHelper when processing the private final void foo.SimpleFooService.someExtensionFunction(java.util.List,int) method:

The extensionFunctionArg argument has the List<String> type associated to it, instead of int

That inconsistency causes AnnotationMetaDataProvider.getTypeParametersCascadingMetaDataForParameterizedType to fail.

Workaround

Workaround is to remove all extension functions on parameterized receiver from the validated class (which may not be desirable).

Build setup

build.gradle.kts

Environment

Hibernate Validator 6.1.5.Final
zulu11.35.15-ca-jdk11.0.5-win_x64 (observed against IBM Java 8 too)
Kotlin 1.3.72
Gradle 6.5.1
Windows 10

Activity

Show:
Frédéric Chuong
August 5, 2020, 3:19 PM

It seems the problem is upstream in the Kotlin compiler when javaParameters = true as such inconsistency can be reproduced without Hibernate Validator by mere use of reflection APIs.

KT-40857 created against the Kotlin project. I guess you could close this issue as the root cause is out of this project scope.

Guillaume Smet
August 5, 2020, 4:39 PM

Hi Frédéric,

I would say we can keep it open until we have an answer from the Kotlin team and we are sure they consider it a Kotlin issue.

Assignee

Unassigned

Reporter

Frédéric Chuong

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

Priority

Minor
Configure