Skip to content

BeanUtils.getParameterNames fails for Kotlin data classes #34760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bclozel opened this issue Apr 15, 2025 · 0 comments
Open

BeanUtils.getParameterNames fails for Kotlin data classes #34760

bclozel opened this issue Apr 15, 2025 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on theme: kotlin An issue related to Kotlin support

Comments

@bclozel
Copy link
Member

bclozel commented Apr 15, 2025

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)
@bclozel bclozel added in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on theme: kotlin An issue related to Kotlin support labels Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on theme: kotlin An issue related to Kotlin support
Projects
None yet
Development

No branches or pull requests

2 participants