public static @Nullable <T> T castToRemote(@Nullable Object object, @NotNull Class<T> clazz) {
    if (object == null || !Proxy.isProxyClass(object.getClass())) return null;
    if (clazz.isInstance(object)) return (T)object;
    final InvocationHandler handler = Proxy.getInvocationHandler(object);
    if (handler instanceof RemoteInvocationHandler) {
      final RemoteInvocationHandler rih = (RemoteInvocationHandler)handler;
      if (clazz.isInstance(rih.myRemote)) {
        return (T)rih.myRemote;
      }
    }
    return null;
  }
public static @Nullable <T> T castToRemote(@Nullable Object object, @NotNull Class<T> clazz)