-
Notifications
You must be signed in to change notification settings - Fork 682
BeanUtils.getPropertyDescriptors(…)
for Kotlin class with Java superclass does not include properties from its superclass
#2994
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
Comments
NotWritablePropertyException
with Spring Boot 3.2JpaRepositoryFactoryBean
written in Kotlin causes NotWritablePropertyException
with Spring Boot 3.2
Did you notice that the JVM name is Your class needs to adhere to Java beans standards by having getters and setters that adhere to that naming scheme. |
Yes, that is on purpose. Otherwise I get an accidental override error from the kotlin side of things. The problem here is, that my kotlin class inherits from a java class and the detector does not recognize the setter as its not a Kotlin property, as it isn't. When looking at the demo project I provided in the previous post, it makes more sense. The demo project is without any methods to showcase the error. It just inherits from the Spring provided |
In 3.2 we introduced |
Yes, thats probably the reason why when defining the properties myself it is able to infer them. Kotlin is normally able to infer such properties from java as well, when they conform to the java bean standard. In the case of I guess this will happen more often for all kind of kotlin class which do extend java classes / interfaces. |
Like you said, properties from a non-Kotlin superclass aren't taken into account by Kotlin reflection. We can add these ourselves by walking the type hierarchy and resolving properties from the superclass using the regular This adds back any inherited properties. |
JpaRepositoryFactoryBean
written in Kotlin causes NotWritablePropertyException
with Spring Boot 3.2BeanUtils.getPropertyDescriptors(…)
for Kotlin class with Java superclass does not include properties from its superclass
We now include properties from non-Kotlin supertypes if the supertype is not a Kotlin type and not Object. Closes #2994
We now include properties from non-Kotlin supertypes if the supertype is not a Kotlin type and not Object. Closes #2994
We now include properties from non-Kotlin supertypes if the supertype is not a Kotlin type and not Object. Closes #2994
I transferred the ticket into Spring Data Commons, where the code for That's also addressed now in |
After updating to Spring Boot 3.2, my Kotlin app does not start anymore with an exception of
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'queryLookupStrategyKey' of bean class [com.example.demo.JpaRepositoryFactoryBeanImpl]: Bean property 'queryLookupStrategyKey' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
.After debugging for some time I found out that in 3.2 there seems to be some new property introspection for kotlin classes and their properties are active. The problem seems to be, that the setters from the super class, in that case
JpaRepositoryFactoryBean
are not recognized as they are not Kotlin properties.I can work around that by including the following code:
Another workaround is writing that class in java, but this defeats the purpose of using Kotlin in the first place.
Attached is a minimal reproducible example: kotlin-jpa-bug.zip
The text was updated successfully, but these errors were encountered: