question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bkielczewskicommented, Mar 22, 2021

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

0reactions
juergenzimmermanncommented, Mar 22, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

No accessor to set property" with kotlin - Stack Overflow
to create a new instance that contains the changed property value. Alternatively: Use Kotlin's data class feature.
Read more >
Kotlin: UnsupportedOperationException for reified generic ...
Kotlin : UnsupportedOperationException for reified generic with get/set operator · I have two Kotlin extension methods for the same class, but with a...
Read more >
spring-projects/spring-data - Gitter
And I'm getting this exception java.lang.UnsupportedOperationException: No accessor to set property @org.springframework.data.annotation.Id()private final java.
Read more >
Data classes | Kotlin
Data classes. It is not unusual to create classes whose main purpose is to hold data. In such classes, some standard functionality and...
Read more >
Groovy Language Documentation
Use this data type for simple flags that track true/false conditions. ... a foo and a Foo property, since they would have the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found