Skip to content

Conversation

@edwardmp
Copy link
Contributor

This commit adds two test cases to demonstrate a bug in Kotlin constructor resolution when dealing with private constructors. The first test case shows the failure scenario where a private constructor without default parameter values causes a runtime exception. The second test case demonstrates that adding default parameter values to the private constructor doesn't display the same issue.

The bug seems to occur because the code incorrectly assumes that private constructors always generate synthetic parameters for both the default mask and the DefaultConstructorMarker. However, when a private primary constructor has no default parameter values, the Kotlin compiler only generates the DefaultConstructorMarker variant, not the mask parameter.

References #3389

This commit adds two test cases to demonstrate a bug in Kotlin constructor resolution when dealing with private constructors. The first test case shows the failure scenario where a private constructor without default parameter values causes a runtime exception. The second test case demonstrates that adding default parameter values to the private constructor doesn't display the same issue.

The bug seems to occur because the code incorrectly assumes that private constructors always generate synthetic parameters for both the default mask and the DefaultConstructorMarker. However, when a private primary constructor has no default parameter values, the Kotlin compiler only generates the DefaultConstructorMarker variant, not the mask parameter.

References spring-projects#3389

Signed-off-by: Edward Poot <edwardmp@gmail.com>
@mp911de mp911de changed the title Add test cases for Kotlin private constructor instantiation edge cases. Add test cases for Kotlin private constructor instantiation edge cases Oct 27, 2025
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 27, 2025
@mp911de mp911de self-assigned this Oct 27, 2025
@mp911de mp911de added this to the 3.5.6 (2025.0.6) milestone Oct 27, 2025
mp911de pushed a commit that referenced this pull request Oct 27, 2025
Add two test cases to demonstrate a bug in Kotlin constructor resolution when dealing with private constructors.

Closes #3389
Original pull request: #3390

Signed-off-by: Edward Poot <edwardmp@gmail.com>
mp911de added a commit that referenced this pull request Oct 27, 2025
Attempt two-pass constructor detection in KotlinInstantiationDelegate to detect private constructors that are not synthetic ones.

See #3389
Original pull request: #3390
mp911de added a commit that referenced this pull request Oct 27, 2025
Refine KotlinInstantiationDelegate design, improve encapsulation to avoid handing in and out values from lookups.

Replace stream usage with loops, remove unused code, avoid duplicate parameter lookups.

See #3389
Original pull request: #3390
mp911de pushed a commit that referenced this pull request Oct 27, 2025
Add two test cases to demonstrate a bug in Kotlin constructor resolution when dealing with private constructors.

Closes #3389
Original pull request: #3390

Signed-off-by: Edward Poot <edwardmp@gmail.com>
mp911de added a commit that referenced this pull request Oct 27, 2025
Attempt two-pass constructor detection in KotlinInstantiationDelegate to detect private constructors that are not synthetic ones.

See #3389
Original pull request: #3390
mp911de added a commit that referenced this pull request Oct 27, 2025
Refine KotlinInstantiationDelegate design, improve encapsulation to avoid handing in and out values from lookups.

Replace stream usage with loops, remove unused code, avoid duplicate parameter lookups.

See #3389
Original pull request: #3390
@mp911de
Copy link
Member

mp911de commented Oct 27, 2025

Thank you for your contribution. That's merged, polished, and backported now.

@mp911de mp911de closed this Oct 27, 2025
@edwardmp
Copy link
Contributor Author

@mp911de great work Mark! Happy to have had a minor contribution in fixing this 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants