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

(fs) Files::copy requires an undocumented permission when copying from the default file system to a non-default file system

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 19
    • 19
    • core-libs
    • 19
    • b26
    • Verified

      Files::copy requires an undocumented permission when copying from the default file system to a non-default file system. This is a change in behaviour from JDK 18 to JDK 19-ea, introduced by JDK-8267820.

      Example reproducer:

      $ cat FileCopyToZip.java
      import java.io.*;
      import java.nio.file.*;
      import java.util.*;

      public class FileCopyToZip {

          public static void main(String... args) throws IOException {
              Path source = Path.of(args[0]);
              Path zip = Path.of("out.zip");
              Map<String,String> env = Map.of("create", String.valueOf(Files.notExists(zip)));
              
              try (FileSystem fileSystem = FileSystems.newFileSystem(zip, env, FileCopyToZip.class.getClassLoader())) {
                  Path p = fileSystem.getPath(source.getFileName().toString());
                  Files.copy(source, p);
              }
          }
      }

      $ /Users/chegar/binaries/jdk-18.jdk/Contents/Home/bin/javac FileCopyToZip.java

      $ cat java.policy
      grant {
          permission java.io.FilePermission "<<ALL FILES>>", "read,write";
      };

      $ /Users/chegar/binaries/jdk-18.jdk/Contents/Home/bin/java -Djava.security.manager -Djava.security.policy=java.policy FileCopyToZip FileCopyToZip.class
      WARNING: A command line option has enabled the Security Manager
      WARNING: The Security Manager is deprecated and will be removed in a future release


      $ /Users/chegar/binaries/jdk-19.jdk/Contents/Home/bin/java -Djava.security.manager -Djava.security.policy=java.policy FileCopyToZip FileCopyToZip.class
      WARNING: A command line option has enabled the Security Manager
      WARNING: The Security Manager is deprecated and will be removed in a future release
      Exception in thread "main" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessUserInformation")
      at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:485)
      at java.base/java.security.AccessController.checkPermission(AccessController.java:1068)
      at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:411)
      at java.base/sun.nio.fs.UnixFileAttributeViews$Posix.checkReadExtended(UnixFileAttributeViews.java:186)
      at java.base/sun.nio.fs.UnixFileAttributeViews$Posix.readAttributes(UnixFileAttributeViews.java:253)
      at java.base/sun.nio.fs.UnixFileAttributeViews$Posix.readAttributes(UnixFileAttributeViews.java:168)
      at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:148)
      at java.base/java.nio.file.Files.readAttributes(Files.java:1851)
      at java.base/java.nio.file.CopyMoveHelper.copyToForeignTarget(CopyMoveHelper.java:114)
      at java.base/java.nio.file.Files.copy(Files.java:1308)
      at FileCopyToZip.main(FileCopyToZip.java:14)
       

            bpb Brian Burkhalter
            chegar Chris Hegarty
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: