code: public static TreePath getPath(TreePath path, Tree target) {
          path.getClass();
          target.getClass();
  
          class Result extends Error {
              static final long serialVersionUID = -5942088234594905625L;
              TreePath path;
              Result(TreePath path) {
                  this.path = path;
              }
          }
  
          class PathFinder extends TreePathScanner<TreePath,Tree> {
              public TreePath scan(Tree tree, Tree target) {
                  if (tree == target) {
                      throw new Result(new TreePath(getCurrentPath(), target));
                  }
                  return super.scan(tree, target);
              }
          }
  
          if (path.getLeaf() == target) {
              return path;
          }
  
          try {
              new PathFinder().scan(path, target);
          } catch (Result result) {
              return result.path;
          }
          return null;
      }
docs: Gets a tree path for a tree node within a subtree identified by a TreePath object.
  @return null if the node is not found