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

UnsupportedOperationException: No accessor to set property for Kotlin data classes using parametrized types #2336

Closed
pkubowicz opened this issue Mar 19, 2021 · 7 comments
Assignees
Labels
type: blocker An issue that is blocking us from releasing type: regression A regression from a previous release

Comments

@pkubowicz
Copy link

pkubowicz commented Mar 19, 2021

To reproduce:

Create an entity using a Kotlin data class:

data class User(
    val id: String? = null,
    val flags: Map<String, Any>,
)

Trying to save an instance with null id will crash:

No accessor to set property private final java.lang.String com.example.User.id!
java.lang.UnsupportedOperationException: No accessor to set property private final java.lang.String com.example.User.id!
	at com.example.User_Accessor_a89b9l.setProperty(Unknown Source)
	at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.setProperty(InstantiationAwarePropertyAccessor.java:104)
	at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:63)
	at org.springframework.data.mongodb.core.EntityOperations$AdaptibleMappedEntity.populateIdIfNecessary(EntityOperations.java:690)

Changing field to Map<String, String> makes the bug disappear. Downgrading to Spring Boot 2.4.3 also removes the exception.

A minimal project reproducing the bug can be found here: https://github.com/pkubowicz/spring-data-id-accessor

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2021
@mp911de mp911de added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 19, 2021
@mp911de mp911de self-assigned this Mar 19, 2021
@bkielczewski
Copy link

bkielczewski commented Mar 21, 2021

That's present since spring-data-commons-2.4.6. In my case this was about collection of enums in the data class entity.
I've replicated that in https://github.com/bkielczewski/spring-data-mongodb-no-accessor

@mp911de
Copy link
Member

mp911de commented Mar 22, 2021

The issue is caused by our copy method resolution which considers the component type in assignability checks while the synthetic copy method resolves to a different type than the Kotlin KType (Copy method java.util.Map<?, ?>, KType java.util.Map<java.lang.String, ?>). Reducing the types to their raw types solves the issue.

@mp911de mp911de changed the title Regression in 2.4.6: 'UnsupportedOperationException: No accessor to set property' for Kotlin data classes UnsupportedOperationException: No accessor to set property for Kotlin data classes using parametrized types Mar 22, 2021
@mp911de mp911de added this to the 2.4.7 (2020.0.7) milestone Mar 22, 2021
@mp911de
Copy link
Member

mp911de commented Mar 22, 2021

Caused by #2324.

@mp911de
Copy link
Member

mp911de commented Mar 22, 2021

Sorry for the inconvenience. We fixed the issue and our CI deployed spring-data-commons-2.4.7-SNAPSHOT.jar into our snapshot repository. Care to upgrade to 2.4.7-SNAPSHOT and retest?

@bkielczewski
Copy link

My test case is passing when i use spring-data-commons-2.4.7-SNAPSHOT. Thanks for fixing.

@juergenzimmermann
Copy link

Using Spring Data Commons 2.5.0-SNAPSHOT my app also works again.

@themafole
Copy link

In my case, it only passed when I added Jackson in my build.gradle: com.fasterxml.jackson.module:jackson-module-kotlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: blocker An issue that is blocking us from releasing type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

7 participants
@juergenzimmermann @mp911de @bkielczewski @pkubowicz @spring-projects-issues @themafole and others