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

java.nio.Path does not support NTFS alternate data streams

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Any Windows OS with NTFS file system.

      A DESCRIPTION OF THE PROBLEM :
      NTFS has the concept of alternate data streams. https://docs.microsoft.com/en-us/archive/blogs/askcore/alternate-data-streams-in-ntfs These streams are represented as a file name with a colon. For example, you might have example.txt and an alternate stream named example.txt:stream1.

      Using the old java.io APIs, it is possible to access these streams. For example, new File("example.txt:stream1").length() returns the length of the alternate stream, not the root file. However, java.nio.Paths.get("example.txt:stream1") throws an InvalidPathException. The JDK WindowsPathParser is written to reject colons in the file path: https://github.com/openjdk/jdk/blob/53b2368d495d865c8b5c4e481a57f6e06a616490/src/java.base/windows/classes/sun/nio/fs/WindowsPathParser.java#L225

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In a CMD prompt:
      echo example > example.txt
      echo hello > example.txt:stream1

      Then run the following Java code:

      File exampleFile = new File("example.txt");
      assert exampleFile.length() == 10;
      File streamFile = new File("example.txt:stream1");
      assert streamFile.length() == 8;

      Path streamPathViaFile = streamFile.toPath();
      Path streamPathViaPaths = Paths.get("example.txt:stream1");

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both assertions pass, and the "program" runs to completion.
      ACTUAL -
      Both assertions pass, but the program throws InvalidPathException when streamFile.toPath() is called.

      CUSTOMER SUBMITTED WORKAROUND :
      I have not found a workaround using the java.nio APIs

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: