Skip to content

Commit 82e8104

Browse files
committed
Ignore getters for Kotlin types deviating from Java Beans spec.
We now ignore Kotlin getters that are either static methods or would require additional arguments. Closes #3109
1 parent 4f5b6dc commit 82e8104

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.beans.PropertyDescriptor;
2929
import java.beans.SimpleBeanInfo;
3030
import java.lang.reflect.Method;
31+
import java.lang.reflect.Modifier;
3132
import java.util.Arrays;
3233
import java.util.LinkedHashSet;
3334
import java.util.Set;
@@ -68,6 +69,10 @@ public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
6869
Method getter = ReflectJvmMapping.getJavaGetter(property);
6970
Method setter = property instanceof KMutableProperty<?> kmp ? ReflectJvmMapping.getJavaSetter(kmp) : null;
7071

72+
if (getter != null && (Modifier.isStatic(getter.getModifiers()) || getter.getParameterCount() != 0)) {
73+
continue;
74+
}
75+
7176
if (getter != null && setter != null && setter.getParameterCount() == 1) {
7277
if (!getter.getReturnType().equals(setter.getParameters()[0].getType())) {
7378
// filter asymmetric getters/setters from being considered a Java Beans property
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.util
17+
18+
@JvmInline
19+
value class InlineClassWithProperty(val value: String) {
20+
val foo: String get() = "foo-$value"
21+
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class KotlinBeanInfoFactoryUnitTests {
4848
}
4949
}
5050

51+
@Test // GH-3109
52+
internal fun considersJavaBeansGettersOnly() {
53+
54+
val pds = BeanUtils.getPropertyDescriptors(InlineClassWithProperty::class.java)
55+
56+
assertThat(pds).hasSize(1).extracting("name").contains("value")
57+
}
58+
5159
@Test
5260
internal fun determinesInlineClassConsumerProperties() {
5361

0 commit comments

Comments
 (0)