private static boolean isDisposed(Window window) {
    Window w = window;
    while (w != null) {
      if (w instanceof DisposableWindow dw && dw.isWindowDisposed()) {
        return true;
      }
      w = w.getOwner();
    }
    return false;
  }
private static boolean isDisposed(Window window)