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

File.toPath() throws an exception when VSS enabled path is encountered

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.10586]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Only happens when dealing with a VSS enabled path

      A DESCRIPTION OF THE PROBLEM :
      Problem occurs when VSS (Volume Shadow Copy) is used on Windows. When VSS is used, a normal folder on Windows becomes from:

      C:\Folder1

      to

      \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy62\Folder1

      The File.toPath() method does not like the ? in the path that is VSS enabled. and throws an error, even though this is a valid path at the OS level. This modified version of the path is accessible using the "File" class but not "Path"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      String myPath = "\\\\?\\GLOBALROOT\\Device\HarddiskVolumeShadowCopy62\\Folder1"
      File aFile = new File(myPath);

      aFile.toPath(); //this throws an exception

      //The value in myPath is a valid path on Windows.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The toPath() method should not throw an Exception. As a result of this exception, I cannot create a "Path" object for this modified version of path and therefore, cannot use several classes in java.nio.* package
      ACTUAL -
      File.toPath() method throws an exception even if the path is valid.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      String myPath = "\\\\?\\GLOBALROOT\\Device\HarddiskVolumeShadowCopy62\\Folder1"
      File aFile = new File(myPath);

      aFile.toPath(); //this throws an exception

      //The value in myPath is a valid path on Windows.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Avoid using java.nio.file.Path interface

      SUPPORT :
      YES

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

              Created:
              Updated: