Unwrap Kotlin inline value classes return values

The result returned by Kotlin reflective invocation of a function
returning an inline value class is wrapped, which makes sense
from Kotlin POV but from a JVM perspective the associated value
and type should be unwrapped to be consistent with what
would happen with a reflective invocation done by Java.

This commit unwraps such result.

Closes gh-33026
This commit is contained in:
Sébastien Deleuze
2024-07-10 18:31:35 +02:00
parent 82c5aa4a48
commit 7617a01f60
6 changed files with 67 additions and 3 deletions

View File

@@ -299,7 +299,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
@Nullable
@SuppressWarnings({"deprecation", "DataFlowIssue"})
public static Object invokeFunction(Method method, Object target, Object[] args) throws InvocationTargetException, IllegalAccessException {
public static Object invokeFunction(Method method, Object target, Object[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
// For property accessors
if (function == null) {
@@ -332,6 +332,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
}
}
Object result = function.callBy(argMap);
if (result != null && KotlinDetector.isInlineClass(result.getClass())) {
return result.getClass().getDeclaredMethod("unbox-impl").invoke(result);
}
return (result == Unit.INSTANCE ? null : result);
}
}