private @NotNull Promise<TreePath> resolve(Promise<? extends TreePath> promise) {
    if (promise == null && isValidThread()) {
      return rejectedPromise();
    }
    AsyncPromise<TreePath> async = new AsyncPromise<>();
    if (promise == null) {
      onValidThread(() -> async.setError("rejected"));
    }
    else {
      promise.onError(onValidThread(async::setError));
      promise.onSuccess(onValidThread(path -> resolve(async, path)));
    }
    return async;
  }
private @NotNull Promise<TreePath> resolve(Promise<? extends TreePath> promise)