Skip to content
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

IndexOutOfBoundsException on KotlinCopyMethod.shouldUsePublicCopyMethod(…) when saving single-property Kotlin data class with Association #3131

Closed
amreivcz-old opened this issue Aug 5, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@amreivcz-old
Copy link

I'm working in a project using Kotlin and JDBC for our service and I'm seeing the following exception when trying to save an object to the database:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.util.Objects.checkIndex(Objects.java:385)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at org.springframework.data.mapping.model.KotlinCopyMethod.shouldUsePublicCopyMethod(KotlinCopyMethod.java:177)

We're trying to save an aggregate that looks something like this:

@Table("some_aggregate")
data class SomeAggregate(
    @Id
    var id: UUID? = null,
    @MappedCollection(idColumn = "objectId")
    val objects: Set<SomeRelatedObject> = emptySet(),
) 

@Table("some_related_object")
data class SomeRelatedObject(
    val relatedObject: AggregateReference<ObjectAggregate, UUID>,
) 

The problem is with the SomeRelatedObject data class, since this has an empty persistentProperties, resulting from relatedObject being an Association. Therefore when iterating over parameterTypes, it throws the IndexOutOfBoundsException.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 5, 2024
@odrotbohm odrotbohm changed the title IndexOutOfBoundsException on KotlinCopyMethod.shouldUsePublicCopyMethod when saving Kotlin data class with Association in JDBC IndexOutOfBoundsException on KotlinCopyMethod.shouldUsePublicCopyMethod(…) when saving Kotlin data class with Association in JDBC Aug 5, 2024
@mp911de mp911de self-assigned this Aug 6, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 6, 2024
@mp911de mp911de changed the title IndexOutOfBoundsException on KotlinCopyMethod.shouldUsePublicCopyMethod(…) when saving Kotlin data class with Association in JDBC IndexOutOfBoundsException on KotlinCopyMethod.shouldUsePublicCopyMethod(…) when saving single-property Kotlin data class with Association Aug 6, 2024
@mp911de mp911de added this to the 3.2.9 (2023.1.9) milestone Aug 6, 2024
mp911de added a commit that referenced this issue Aug 6, 2024
KotlinCopyMethod.shouldUsePublicCopyMethod(…) now considers single-association arrangements. Also, the method now early exists if pre-conditions aren't met.

Closes #3131
@mp911de mp911de closed this as completed in 1cdfb2e Aug 6, 2024
mp911de added a commit that referenced this issue Aug 6, 2024
KotlinCopyMethod.shouldUsePublicCopyMethod(…) now considers single-association arrangements. Also, the method now early exists if pre-conditions aren't met.

Closes #3131
@mp911de
Copy link
Member

mp911de commented Aug 6, 2024

That's fixed now. Care to test against the latest snapshots (note that you must explicitly specify the dependency version of spring-data-commons)?

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

No branches or pull requests

3 participants