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

(fs) FileSystemProvider should use FILE_FLAG_OPEN_NO_RECALL option (win32)

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      Windows 11

      OneDrive

      GraalVM 11.0.12
      Zulu 11.52.13
      Not tested, but from reading the source bug also seems present in OpenJDK 17 as well.




      A DESCRIPTION OF THE PROBLEM :
      When calling Files.listfiles(...) cloud only files are automatically downloaded to local storage.

      At Line ~168 of sun.nio.fs.WindowsChannelFactory the following line opens the file handle.

      FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor);

      It's missing the FILE_FLAG_OPEN_NO_RECALL flag as noted in the win32 api.

      https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea

      The flag is missing from sun.nio.fs.WindowsConstants as well.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run java.nio.file.Files.listFiles on any folder in OneDrive with files that are not stored locally.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A listing of files in the directory.
      ACTUAL -
      A listing of files in the directory with each remote file forced to download.

      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.Path;


      public class NIOProblem {
          public static void main(String[] args) throws IOException {
              //This assumes windows with one drive remote files
              //(may affect other storage systems using the same api idk)
              Files.list(Path.of(System.getProperty("user.home"), "OneDrive"));
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Not using java.nio.file.Files.listFiles() to list files.
      Using java.​io.​File.listFiles() instead.

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: