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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user