From 3290592f5866b8b62fd6ce43607a9d9a79b8d40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Wed, 28 May 2025 14:39:39 +0200 Subject: [PATCH] Remove Kotlin field handling in DependencyDescriptor The KotlinDelegate#isNullable invocation is unnecessary since this check is already done by the Nullness#forField one introduced by b5d153febf7395658a53c2fac08f342781b6cc8f. See gh-34952 See gh-34261 --- .../factory/config/DependencyDescriptor.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java index de62d5e7ab6..617cbf05802 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java @@ -24,15 +24,12 @@ import java.lang.reflect.Field; import java.util.Map; import java.util.Optional; -import kotlin.reflect.KProperty; -import kotlin.reflect.jvm.ReflectJvmMapping; import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.InjectionPoint; import org.springframework.beans.factory.NoUniqueBeanDefinitionException; -import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.Nullness; import org.springframework.core.ParameterNameDiscoverer; @@ -163,8 +160,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable } if (this.field != null) { - return !(this.field.getType() == Optional.class || Nullness.forField(this.field) == Nullness.NULLABLE || - (KotlinDetector.isKotlinType(this.field.getDeclaringClass()) && KotlinDelegate.isNullable(this.field))); + return !(this.field.getType() == Optional.class || Nullness.forField(this.field) == Nullness.NULLABLE); } else { return !obtainMethodParameter().isOptional(); @@ -446,19 +442,4 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable } } - - /** - * Inner class to avoid a hard dependency on Kotlin at runtime. - */ - private static class KotlinDelegate { - - /** - * Check whether the specified {@link Field} represents a nullable Kotlin type or not. - */ - public static boolean isNullable(Field field) { - KProperty property = ReflectJvmMapping.getKotlinProperty(field); - return (property != null && property.getReturnType().isMarkedNullable()); - } - } - }