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

(fs) Path.toRealPath(LinkOption.NOFOLLOW_LINKS) fails when "../../" follows a link (win)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 22
    • core-libs
    • None

      A similar issue as reported for Unix in JDK-8306882.

      If one has these files

      ./dir/subdir
      ./aaa@ -> dir/subdir
      ./out.txt

      then trying to get the real path of "aaa/../../out.txt" in jshell gives:

      jshell> Path p = Path.of("aaa/../../out.txt")
      p ==> aaa\..\..\out.txt

      jshell> p.toRealPath()
      | Exception java.nio.file.NoSuchFileException: C:\Users\out.txt
      | at WindowsException.translateToIOException (WindowsException.java:85)
      | at WindowsException.rethrowAsIOException (WindowsException.java:96)
      | at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:288)
      | at WindowsPath.toRealPath (WindowsPath.java:944)
      | at WindowsPath.toRealPath (WindowsPath.java:42)
      | at (#2:1)

      jshell> p.toRealPath(LinkOption.NOFOLLOW_LINKS)
      | Exception java.nio.file.NoSuchFileException: C:\Users\out.txt
      | at WindowsException.translateToIOException (WindowsException.java:85)
      | at WindowsException.rethrowAsIOException (WindowsException.java:96)
      | at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:288)
      | at WindowsPath.toRealPath (WindowsPath.java:944)
      | at WindowsPath.toRealPath (WindowsPath.java:42)
      | at (#3:1)

      Therefore toRealPath() fails whether or not links are followed.

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: