private static boolean isUnderExcluded(File root, Set<? extends File> excluded, Set<? super File> notUnderExcludedCache) {
    File parent = root;
    List<File> parents = new ArrayList<>();
    while (parent != null) {
      if (notUnderExcludedCache.contains(parent)) {
        return false;
      }
      if (excluded.contains(parent)) {
        return true;
      }
      parents.add(parent);
      parent = parent.getParentFile();
    }
    notUnderExcludedCache.addAll(parents);
    return false;
  }
private static boolean isUnderExcluded(File root, Set<? extends File> excluded, Set<? super File> notUnderExcludedCache)