Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8069345

(fs) FileTreeWalker throws NotDirectoryException on file junction points

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • core-libs
    • None
    • jdk 8 build 1.8.0-b132

    • Cause Known
    • x86
    • windows_7

      On windows!
      Suppose I have a folder "test" containing two files, one standard file.txt, and second a junction point (created by sysinternals junction.exe) to the first file (created junction.exe filejunction file.txt). Here is "dir" executed in the folder:
      {quote}
      19.01.2015 23:58 0 file.txt
      20.01.2015 00:03 <JUNCTION> filejunction [\??\c:\test\file.txt]
      {quote}
      The following code:
      {code:java}
      File f = new File("c:\\test\\filejunction");
      Path p = f.toPath();
                      Files.walkFileTree(p.getParent(), new SimpleFileVisitor<Path>(){});
      {code}
      {quote}
       java.nio.file.NotDirectoryException: c:\test\filejunction
      at sun.nio.fs.WindowsDirectoryStream.<init>(WindowsDirectoryStream.java:84)
      at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(WindowsFileSystemProvider.java:510)
      at java.nio.file.Files.newDirectoryStream(Files.java:457)
      at java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:300)
      at java.nio.file.FileTreeWalker.next(FileTreeWalker.java:372)
      at java.nio.file.Files.walkFileTree(Files.java:2703)
      at java.nio.file.Files.walkFileTree(Files.java:2739)
      {quote}
      It appears there is something wrong with attributes. The method FileTreeWalker#visit contains:
      {code:java}
              if (depth >= maxDepth || !attrs.isDirectory()) {
                  return new Event(EventType.ENTRY, entry, attrs);
              }
      {code}
      and WindowsFileAttributes#isDirectory contains:
      {code:java}
      return ((fileAttrs & FILE_ATTRIBUTE_DIRECTORY) != 0)
      {code}
      hence in this case: return ((fileAttrs = 1040) & 16) !=0 which is true.

      It can be problem with attributes caching (in BasicFileAttributesHolder), because the following code returns {{false}}:
      {code:java}
      BasicFileAttributes attr = Files.readAttributes(p, BasicFileAttributes.class);
      attr.isDirectory()
      {code}

            bpb Brian Burkhalter
            jsupol Jan Supol
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: