Merge branch '6.1.x'
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.web.method.support;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,6 +26,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;
|
||||
|
||||
@@ -37,10 +37,8 @@ import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
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.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.support.SessionStatus;
|
||||
@@ -64,9 +62,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
|
||||
private static final Class<?>[] EMPTY_GROUPS = new Class<?>[0];
|
||||
|
||||
private static final ReflectionUtils.MethodFilter boxImplFilter =
|
||||
(method -> method.isSynthetic() && Modifier.isStatic(method.getModifiers()) && method.getName().equals("box-impl"));
|
||||
|
||||
|
||||
private HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
@@ -322,10 +317,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]);
|
||||
@@ -342,6 +334,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
Object result = function.callBy(argMap);
|
||||
return (result == Unit.INSTANCE ? null : result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,17 +87,24 @@ class InvocableHandlerMethodKotlinTests {
|
||||
@Test
|
||||
fun valueClass() {
|
||||
composite.addResolver(StubArgumentResolver(Long::class.java, 1L))
|
||||
val value = getInvocable(Handler::class.java, Long::class.java).invokeForRequest(request, null)
|
||||
val value = getInvocable(ValueClassHandler::class.java, Long::class.java).invokeForRequest(request, null)
|
||||
Assertions.assertThat(value).isEqualTo(1L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun valueClassDefaultValue() {
|
||||
composite.addResolver(StubArgumentResolver(Double::class.java))
|
||||
val value = getInvocable(Handler::class.java, Double::class.java).invokeForRequest(request, null)
|
||||
val value = getInvocable(ValueClassHandler::class.java, Double::class.java).invokeForRequest(request, null)
|
||||
Assertions.assertThat(value).isEqualTo(3.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun valueClassWithInit() {
|
||||
composite.addResolver(StubArgumentResolver(String::class.java, ""))
|
||||
val invocable = getInvocable(ValueClassHandler::class.java, String::class.java)
|
||||
Assertions.assertThatIllegalArgumentException().isThrownBy { invocable.invokeForRequest(request, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun propertyAccessor() {
|
||||
val value = getInvocable(PropertyAccessorHandler::class.java).invokeForRequest(request, null)
|
||||
@@ -153,11 +160,19 @@ class InvocableHandlerMethodKotlinTests {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ValueClassHandler {
|
||||
|
||||
fun valueClass(limit: LongValueClass) =
|
||||
limit.value
|
||||
|
||||
fun valueClass(limit: DoubleValueClass = DoubleValueClass(3.1)) =
|
||||
limit.value
|
||||
|
||||
fun valueClassWithInit(valueClass: ValueClassWithInit) =
|
||||
valueClass
|
||||
|
||||
}
|
||||
|
||||
private class PropertyAccessorHandler {
|
||||
@@ -183,6 +198,15 @@ 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