private static @NotNull RemoteCallResult getRemoteCallResult(@NotNull Session session, @NotNull CallTarget callTarget, Object result) {
    Method targetMethod = callTarget.targetMethod();

    if (Collection.class.isAssignableFrom(targetMethod.getReturnType())) {
      Type returnType = targetMethod.getGenericReturnType();

      if (returnType instanceof ParameterizedType) {
        Type[] typeArguments = ((ParameterizedType)returnType).getActualTypeArguments();
        if (typeArguments.length == 1 && typeArguments[0] instanceof Class<?> componentType) {
          if (isPassByValue(componentType)) {
            return new RemoteCallResult(result);
          }
        }
      }
    }
    else if (targetMethod.getReturnType().isArray()) {
      if (isPassByValue(targetMethod.getReturnType().getComponentType())) {
        return new RemoteCallResult(result);
      }
    }

    return getRemoteCallResult(session, result);
  }
private static @NotNull RemoteCallResult getRemoteCallResult(@NotNull Session session, @NotNull CallTarget callTarget, Object result)