Omit asymmetric Kotlin properties.
We now skip adding asymmetric Kotlin properties if the getter returns a different type than the setter (e.g. due to value boxing). Closes #2993
This commit is contained in:
@@ -68,6 +68,13 @@ public class KotlinBeanInfoFactory implements BeanInfoFactory, Ordered {
|
||||
Method getter = ReflectJvmMapping.getJavaGetter(property);
|
||||
Method setter = property instanceof KMutableProperty<?> kmp ? ReflectJvmMapping.getJavaSetter(kmp) : null;
|
||||
|
||||
if (getter != null && setter != null && setter.getParameterCount() == 1) {
|
||||
if (!getter.getReturnType().equals(setter.getParameters()[0].getType())) {
|
||||
// filter asymmetric getters/setters from being considered a Java Beans property
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
pds.add(new PropertyDescriptor(property.getName(), getter, setter));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,16 @@ class KotlinBeanInfoFactoryUnitTests {
|
||||
assertThat(pds).extracting("name").contains("myQueryLookupStrategyKey", "repositoryBaseClass")
|
||||
}
|
||||
|
||||
@Test // GH-2993
|
||||
internal fun skipsAsymmetricGettersAndSetters() {
|
||||
|
||||
val pds = BeanUtils.getPropertyDescriptors(MyEntity::class.java)
|
||||
|
||||
assertThat(pds).hasSize(1)
|
||||
assertThat(pds[0].writeMethod).isNull()
|
||||
assertThat(pds[0].readMethod).isNotNull()
|
||||
}
|
||||
|
||||
data class SimpleDataClass(val id: String, var name: String)
|
||||
|
||||
@JvmInline
|
||||
@@ -123,4 +133,12 @@ class KotlinBeanInfoFactoryUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
interface Interval<T> {
|
||||
val end: T
|
||||
}
|
||||
|
||||
class MyEntity : Interval<Long> {
|
||||
override var end: Long = -1L
|
||||
protected set
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user