private static @NotNull Path optionallyChangeRoot(@Nullable Path rootPath, @NotNull Path dir) {
    return rootPath != null ? rootPath.resolve(dir.getRoot().relativize(dir)) : dir;
  }
private static @NotNull Path optionallyChangeRoot(@Nullable Path rootPath, @NotNull Path dir)