diff --git a/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java b/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java index f7d00fc09..050100621 100644 --- a/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java +++ b/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java @@ -28,6 +28,7 @@ import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.beans.SimpleBeanInfo; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; @@ -70,6 +71,10 @@ public class KotlinBeanInfoFactory implements BeanInfoFactory, Ordered { Method getter = ReflectJvmMapping.getJavaGetter(property); Method setter = property instanceof KMutableProperty kmp ? ReflectJvmMapping.getJavaSetter(kmp) : null; + if (getter != null && (Modifier.isStatic(getter.getModifiers()) || getter.getParameterCount() != 0)) { + continue; + } + 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 diff --git a/src/test/kotlin/org/springframework/data/util/InlineClassWithProperty.kt b/src/test/kotlin/org/springframework/data/util/InlineClassWithProperty.kt new file mode 100644 index 000000000..96af7b987 --- /dev/null +++ b/src/test/kotlin/org/springframework/data/util/InlineClassWithProperty.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.util + +@JvmInline +value class InlineClassWithProperty(val value: String) { + val foo: String get() = "foo-$value" +} diff --git a/src/test/kotlin/org/springframework/data/util/KotlinBeanInfoFactoryUnitTests.kt b/src/test/kotlin/org/springframework/data/util/KotlinBeanInfoFactoryUnitTests.kt index 659f3a300..ada3014b6 100644 --- a/src/test/kotlin/org/springframework/data/util/KotlinBeanInfoFactoryUnitTests.kt +++ b/src/test/kotlin/org/springframework/data/util/KotlinBeanInfoFactoryUnitTests.kt @@ -48,6 +48,14 @@ class KotlinBeanInfoFactoryUnitTests { } } + @Test // GH-3109 + internal fun considersJavaBeansGettersOnly() { + + val pds = BeanUtils.getPropertyDescriptors(InlineClassWithProperty::class.java) + + assertThat(pds).hasSize(1).extracting("name").contains("value") + } + @Test internal fun determinesInlineClassConsumerProperties() {