Skip to content

BeanUtils.getParameterNames fails for Kotlin data classes #34760

Open
@bclozel

Description

@bclozel

While working on spring-projects/spring-graphql#1186, I have noticed that BeanUtils.getParameterNames(Constructor) checks that the number of detected parameter names is equal to the number of constructor arguments detected via Java reflection.

In the case of Kotlin data classes, there is an additional kotlin.jvm.internal.DefaultConstructorMarker constructor argument which fails with the following:

Invalid number of parameter names: 1 for constructor public org.springframework.beans.BeanUtilsKotlinTests$ConstructorWithValueClass(java.lang.String,kotlin.jvm.internal.DefaultConstructorMarker)
java.lang.IllegalStateException: Invalid number of parameter names: 1 for constructor public org.springframework.beans.BeanUtilsKotlinTests$ConstructorWithValueClass(java.lang.String,kotlin.jvm.internal.DefaultConstructorMarker)

We can reproduce this with:

@Test
fun `Detect constructor parameter names`() {
	val constructor = BeanUtils.getResolvableConstructor(ConstructorWithValueClass::class.java)
	BeanUtils.getParameterNames(constructor)
}

data class ConstructorWithValueClass(val value: ValueClass)

@JvmInline
value class ValueClass(private val value: String)

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: kotlinAn issue related to Kotlin supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions