private boolean wouldLoop(Path dir,Object key){
  for (  DirectoryNode ancestor : stack) {
    Object ancestorKey=ancestor.key();
    if (key != null && ancestorKey != null) {
      if (key.equals(ancestorKey)) {
        return true;
      }
    }
 else {
      try {
        if (Files.isSameFile(dir,ancestor.directory())) {
          return true;
        }
      }
 catch (      IOException|SecurityException x) {
      }
    }
  }
  return false;
}

private boolean wouldLoop ( Path dir , Object key ) { for ( DirectoryNode ancestor : stack ) { Object ancestorKey = ancestor . key ( ) ; if ( key != null && ancestorKey != null ) { if ( key . equals ( ancestorKey ) ) { return true ; } } else { try { if ( Files . isSameFile ( dir , ancestor . directory ( ) ) ) { return true ; } } catch ( IOException | SecurityException x ) { } } } return false ; }
returns true if walking into the given directory would result in a file system loop / cycle .
