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

File::getCanonicalFile doesn't work for \\?\C:\ style paths DOS device paths

XMLWordPrintable

    • b24
    • x86_64
    • windows
    • Verified

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11

      A DESCRIPTION OF THE PROBLEM :
      File::getCanonicalFile incorrectly fails with "java.io.IOException: The handle is invalid" even though File::exists and File::listFiles (i.e. all other file system access method) all work just fine the file path is a \\?\ style file paths (https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      File f = new File("\\\\?\\C:\\Users");
      System.out.println(f.exists());
      System.out.println(f.getCanonicalFile());


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      true
      \\?\C:\Users
      ACTUAL -
      true
      java.io.IOException: The handle is invalid

      ---------- BEGIN SOURCE ----------
      import java.io.File;

      public class Main {

      public static void main(String[] args) throws Exception {
      File f = new File("\\\\?\\C:\\Users");
      System.out.println(f.exists());
      System.out.println(f.getCanonicalFile());
      }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: