Merge branch '6.1.x'
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.web.reactive.result.method;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,6 +31,7 @@ import kotlin.jvm.JvmClassMappingKt;
|
||||
import kotlin.reflect.KClass;
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.KParameter;
|
||||
import kotlin.reflect.full.KClasses;
|
||||
import kotlin.reflect.jvm.KCallablesJvm;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -46,10 +46,8 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.validation.method.MethodValidator;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
@@ -74,9 +72,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
|
||||
private static final Object NO_ARG_VALUE = new Object();
|
||||
|
||||
private static final ReflectionUtils.MethodFilter boxImplFilter =
|
||||
(method -> method.isSynthetic() && Modifier.isStatic(method.getModifiers()) && method.getName().equals("box-impl"));
|
||||
|
||||
|
||||
private final HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
@@ -333,10 +328,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
if (parameter.getType().getClassifier() instanceof KClass<?> kClass) {
|
||||
Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass);
|
||||
if (KotlinDetector.isInlineClass(javaClass)) {
|
||||
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(javaClass, boxImplFilter);
|
||||
Assert.state(methods.length == 1,
|
||||
"Unable to find a single box-impl synthetic static method in " + javaClass.getName());
|
||||
argMap.put(parameter, ReflectionUtils.invokeMethod(methods[0], null, args[index]));
|
||||
argMap.put(parameter, KClasses.getPrimaryConstructor(kClass).call(args[index]));
|
||||
}
|
||||
else {
|
||||
argMap.put(parameter, args[index]);
|
||||
@@ -354,6 +346,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
return (result == Unit.INSTANCE ? null : result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.result
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.delay
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.core.MethodParameter
|
||||
@@ -41,6 +42,7 @@ import reactor.core.publisher.Mono
|
||||
import reactor.test.StepVerifier
|
||||
import java.lang.reflect.Method
|
||||
import java.time.Duration
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.javaMethod
|
||||
|
||||
/**
|
||||
@@ -197,6 +199,14 @@ class InvocableHandlerMethodKotlinTests {
|
||||
assertHandlerResultValue(result, "3.1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun valueClassWithInit() {
|
||||
this.resolvers.add(stubResolver("", String::class.java))
|
||||
val method = ValueClassController::valueClassWithInit.javaMethod!!
|
||||
val result = invoke(ValueClassController(), method)
|
||||
assertExceptionThrown(result, IllegalArgumentException::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun propertyAccessor() {
|
||||
this.resolvers.add(stubResolver(null, String::class.java))
|
||||
@@ -256,6 +266,10 @@ class InvocableHandlerMethodKotlinTests {
|
||||
}.verifyComplete()
|
||||
}
|
||||
|
||||
private fun assertExceptionThrown(mono: Mono<HandlerResult>, exceptionClass: KClass<out Throwable>) {
|
||||
StepVerifier.create(mono).verifyError(exceptionClass.java)
|
||||
}
|
||||
|
||||
class CoroutinesController {
|
||||
|
||||
suspend fun singleArg(q: String?): String {
|
||||
@@ -320,6 +334,9 @@ class InvocableHandlerMethodKotlinTests {
|
||||
fun valueClassWithDefault(limit: DoubleValueClass = DoubleValueClass(3.1)) =
|
||||
"${limit.value}"
|
||||
|
||||
fun valueClassWithInit(valueClass: ValueClassWithInit) =
|
||||
valueClass
|
||||
|
||||
}
|
||||
|
||||
class PropertyAccessorController {
|
||||
@@ -346,5 +363,14 @@ class InvocableHandlerMethodKotlinTests {
|
||||
@JvmInline
|
||||
value class DoubleValueClass(val value: Double)
|
||||
|
||||
@JvmInline
|
||||
value class ValueClassWithInit(val value: String) {
|
||||
init {
|
||||
if (value.isEmpty()) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CustomException(message: String) : Throwable(message)
|
||||
}
|
||||
Reference in New Issue
Block a user