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

(zipfs) ReadOnlyFileSystemException accessing a zip file on a Windows remote directory

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows with access to an UNC share. The bug was originally found in 8, and is still present in Java 12.

      A DESCRIPTION OF THE PROBLEM :
      When creating a zip file on a remote directory with the code below,

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In Windows, run the program below with a file name that points to a file which would be on a remote directory, either an UNC path (like \\server\share\foo.zip) or a drive letter that maps to a share.
      You can call the program with a local path to see that the code is working.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      ZIP file is created with a zip entry inside.
      ACTUAL -
      Exception in thread "main" java.nio.file.ReadOnlyFileSystemException
              at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.checkWritable(ZipFileSystem.java:158)
              at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.newOutputStream(ZipFileSystem.java:519)
              at jdk.zipfs/jdk.nio.zipfs.ZipPath.newOutputStream(ZipPath.java:848)
              at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newOutputStream(ZipFileSystemProvider.java:280)
              at java.base/java.nio.file.Files.newOutputStream(Files.java:222)
              at ZipFileSystemTest.main(ZipFileSystemTest.java:14)

      ---------- BEGIN SOURCE ----------
      import java.net.URI;
      import java.nio.file.FileSystems;
      import java.nio.file.Files;
      import java.nio.file.Paths;
      import java.nio.file.StandardOpenOption;
      import java.util.HashMap;
      import java.util.Map;

      public class ZipFileSystemTest {

          public static void main(String[] args) throws Exception {
              final Map<String, Object> env = new HashMap<>();
              env.put("create", "true");
              Files.newOutputStream(FileSystems.newFileSystem(URI.create("jar:" + Paths.get(args[0]).toUri()), env).getPath("entry"),
                      StandardOpenOption.CREATE_NEW);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can avoid the problem by switching the readOnly private member of ZipFileSystem to true via reflection (tested in Java 8).

      FREQUENCY : always


        Attachments

        1. JI9060076.java
          0.6 kB
        2. screenshot1.jpg
          screenshot1.jpg
          42 kB
        3. screenshot2.jpg
          screenshot2.jpg
          71 kB

          Activity

            People

            • Assignee:
              lancea Lance Andersen
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: