Skip to content

Fix #34760: ignore Kotlin DefaultConstructorMarker in BeanUtils#getParameterNames #34860

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Emil-Stampfly-He
Copy link

Issue#34760

Description

When a Kotlin value class is used as a constructor parameter, the compiler generates an extra synthetic parameter of type kotlin.jvm.internal.DefaultConstructorMarker.

When this step is executed:

@Nullable String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));

It will call KotlinReflectionParameterNameDiscoverer#getParameterNames(List<KParameter>), where ReflectJvmMapping#getKotlinFunction is called to convert a constructor into a function. DefaultConstructorMarker will be dropped after the conversion. This then causes a mismatch between the number of parameter names discovered and the actual constructor parameter count in BeanUtils#getParameterNames:

Assert.state(paramNames.length == ctor.getParametersCount(),
            () -> "Invalid number of parameter names: " + paramNames.length + " for constructor " + ctor);

Since DefaultConstructorMarker exists solely to prevent signature clashes, it is safe to exclude it from the parameter count. Similar thought as in: Ignore binding Kotlin synthetic default constructors

Proposed Change

Replace the existing assertion with:

long realParamsCount = Arrays.stream(ctor.getParameters())
        .filter(p -> !DefaultConstructorMarker.class.equals(p.getType()))
        .count();
Assert.state(paramNames.length == realParamsCount,
        () -> "Invalid number of parameter names: " + paramNames.length + " for constructor " + ctor);

Tests

Added new cases to BeanUtilsKotlinTests to test BeanUtils#getParameterNames.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 7, 2025
…sName (spring-projects#34760)

Mismatch caused by DefaultConstructorMarker, which is now filtered out.
Signed-off-by: EmilSt <[email protected]>
@bclozel bclozel requested a review from sdeleuze May 7, 2025 12:20
@bclozel bclozel added the theme: kotlin An issue related to Kotlin support label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging this pull request may close these issues.

3 participants