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
This commit is contained in:
Sébastien Deleuze 2025-05-28 14:39:39 +02:00
parent 26ee30ed8f
commit 3290592f58
1 changed files with 1 additions and 20 deletions

View File

@ -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());
}
}
}