mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Fix nullable value class handling in CoroutinesUtils
Closes gh-36449 Signed-off-by: T45K <tasktas9@gmail.com>
This commit is contained in:
@@ -134,7 +134,7 @@ public abstract class CoroutinesUtils {
|
||||
Object arg = args[index];
|
||||
if (!(parameter.isOptional() && arg == null)) {
|
||||
KType type = parameter.getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) &&
|
||||
if (!type.isMarkedNullable() &&
|
||||
type.getClassifier() instanceof KClass<?> kClass &&
|
||||
KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
|
||||
arg = box(kClass, arg);
|
||||
@@ -166,7 +166,7 @@ public abstract class CoroutinesUtils {
|
||||
private static Object box(KClass<?> kClass, @Nullable Object arg) {
|
||||
KFunction<?> constructor = Objects.requireNonNull(KClasses.getPrimaryConstructor(kClass));
|
||||
KType type = constructor.getParameters().get(0).getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) &&
|
||||
if (!type.isMarkedNullable() &&
|
||||
type.getClassifier() instanceof KClass<?> parameterClass &&
|
||||
KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(parameterClass))) {
|
||||
arg = box(parameterClass, arg);
|
||||
|
||||
@@ -229,6 +229,13 @@ class CoroutinesUtilsTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
suspend fun invokeSuspendingFunctionWithNullableValueClassParameterWithNonnullObject() {
|
||||
val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithNullableValueClass") }
|
||||
val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, ValueClass("foo"), null) as Mono
|
||||
Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo")
|
||||
}
|
||||
|
||||
@Test
|
||||
suspend fun invokeSuspendingFunctionWithNullableValueClassParameter() {
|
||||
val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithNullableValueClass") }
|
||||
|
||||
Reference in New Issue
Block a user