Browse Source

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
b5d153febf.

See gh-34952
See gh-34261
pull/34959/head
Sébastien Deleuze 10 months ago
parent
commit
3290592f58
  1. 21
      spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

21
spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

@ -24,15 +24,12 @@ import java.lang.reflect.Field; @@ -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 @@ -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 @@ -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());
}
}
}

Loading…
Cancel
Save