Recursively box/unbox nested inline value classes
See gh-34592 Signed-off-by: Dmitry Sulman <dmitry.sulman@gmail.com>
This commit is contained in:
committed by
Sébastien Deleuze
parent
c6a9aa59a3
commit
0c2ba4e38e
@@ -23,6 +23,7 @@ import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import kotlin.Unit;
|
||||
@@ -361,11 +362,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
KType type = parameter.getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass
|
||||
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
|
||||
KFunction<?> constructor = KClasses.getPrimaryConstructor(kClass);
|
||||
if (!KCallablesJvm.isAccessible(constructor)) {
|
||||
KCallablesJvm.setAccessible(constructor, true);
|
||||
}
|
||||
arg = constructor.call(arg);
|
||||
arg = box(kClass, arg);
|
||||
}
|
||||
argMap.put(parameter, arg);
|
||||
}
|
||||
@@ -381,6 +378,19 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
}
|
||||
}
|
||||
|
||||
private static Object box(KClass<?> kClass, Object arg) {
|
||||
KFunction<?> constructor = Objects.requireNonNull(KClasses.getPrimaryConstructor(kClass));
|
||||
KType type = constructor.getParameters().get(0).getType();
|
||||
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> parameterClass
|
||||
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(parameterClass))) {
|
||||
arg = box(parameterClass, arg);
|
||||
}
|
||||
if (!KCallablesJvm.isAccessible(constructor)) {
|
||||
KCallablesJvm.setAccessible(constructor, true);
|
||||
}
|
||||
return constructor.call(arg);
|
||||
}
|
||||
|
||||
private static void handleResult(Object result, SynchronousSink<Object> sink) {
|
||||
if (KotlinDetector.isInlineClass(result.getClass())) {
|
||||
try {
|
||||
@@ -401,7 +411,11 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
}
|
||||
|
||||
private static Object unbox(Object result) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
return result.getClass().getDeclaredMethod("unbox-impl").invoke(result);
|
||||
Object unboxed = result.getClass().getDeclaredMethod("unbox-impl").invoke(result);
|
||||
if (KotlinDetector.isInlineClass(unboxed.getClass())) {
|
||||
return unbox(unboxed);
|
||||
}
|
||||
return unboxed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user