Skip to content

Commit f060bcf

Browse files
committed
Back off from Kotlin BeanInfo creation for interfaces.
KotlinBeanInfoFactory no longer creates a BeanInfo for interfaces to follow general BeanInfo semantics. Closes #2964
1 parent 5dbd956 commit f060bcf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ public class KotlinBeanInfoFactory implements BeanInfoFactory, Ordered {
4848
@Override
4949
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
5050

51+
if (beanClass.isInterface()) {
52+
return null; // back-off to leave interface-based properties to the default mechanism.
53+
}
54+
5155
if (!KotlinDetector.isKotlinReflectPresent() || !KotlinDetector.isKotlinType(beanClass)) {
5256
return null;
5357
}
5458

59+
5560
KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(beanClass);
5661
List<PropertyDescriptor> pds = new ArrayList<>();
5762

src/test/kotlin/org/springframework/data/util/KotlinBeanInfoFactoryUnitTests.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class KotlinBeanInfoFactoryUnitTests {
6565
assertThat(pds[0].writeMethod).isNull()
6666
}
6767

68+
@Test // GH-2964
69+
internal fun backsOffForInterfaces() {
70+
71+
val pds = BeanUtils.getPropertyDescriptors(FirstnameOnly::class.java)
72+
73+
assertThat(pds).hasSize(1).extracting("name").containsOnly("firstname")
74+
}
75+
6876
data class SimpleDataClass(val id: String, var name: String)
6977

7078
@JvmInline
@@ -74,4 +82,8 @@ class KotlinBeanInfoFactoryUnitTests {
7482

7583
data class WithOptionalValueClass(val address: EmailAddress? = EmailAddress("un@known"))
7684

85+
interface FirstnameOnly {
86+
fun getFirstname(): String
87+
}
88+
7789
}

0 commit comments

Comments
 (0)