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

Path::toRealPath does not behave as expected when using ramdisk utility

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 22H2

      A DESCRIPTION OF THE PROBLEM :
      Path::toRealPath cannot return a "real" path for a file that is inside of a directory that is a symbolic link.
      Observed when zip file system is used as the provider relies on this function.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      mkdir C:\new_dir
      mkdir C:\old_dir
      mklink /D C:\old_dir C:\new_dir
      cd new_dir
      type NUL > file.txt

      java.nio.file.Path.of("C:\\old_dir\\file.txt").toRealPath()

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "C:\new_dir\file.txt" is returned as a real path
      ACTUAL -
      | Exception java.nio.file.FileSystemException: C:\old_dir\file.txt: Incorrect function
      | at WindowsException.translateToIOException (WindowsException.java:92)
      | at WindowsException.rethrowAsIOException (WindowsException.java:103)
      | at WindowsException.rethrowAsIOException (WindowsException.java:108)
      | at WindowsLinkSupport.getFinalPath (WindowsLinkSupport.java:112)
      | at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:271)
      | at WindowsPath.toRealPath (WindowsPath.java:944)
      | at WindowsPath.toRealPath (WindowsPath.java:42)
      | at (#17:1)

      ---------- BEGIN SOURCE ----------
      java.nio.file.Path.of("C:\\old_dir\\file.txt").toRealPath()
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Somewhat of an "alternative".
      public static Path toRealPath(Path path) throws IOException {
      if (!Files.exists(path))
      return path;
      loop:
      do {
      var parent = path;
      while ((parent = parent.getParent()) != null) {
      try {
      var source = Files.readSymbolicLink(parent);
      path = source.resolve(parent.relativize(path));
      continue loop;
      } catch (NotLinkException _) {
      }
      }
      return path;
      } while (true);
      }

      FREQUENCY : always


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: