(zipfs) FileSystems.newFileSystem(URI, Map, Loader) can not create new zip file

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P3
    • None
    • Affects Version/s: 7
    • Component/s: core-libs
    • None
    • generic
    • generic

      I try to create a new zip file using FileSystems.newFileSystem(URI, Map, null).
      In Map it contains <"create", "true">. And run it in windows.

      The method throws below exception, not sure whether it is a bug:
      ========================================
      java.lang.IllegalArgumentException: Path component should be '/'
      at sun.nio.fs.WindowsFileSystemProvider.checkUri(WindowsFileSystemProvider.java:68)
      at sun.nio.fs.WindowsFileSystemProvider.newFileSystem(WindowsFileSystemProvider.java:79)
      at java.nio.file.FileSystems.newFileSystem(FileSystems.java:322)
      at ZipfsNewFileSystem.main(ZipfsNewFileSystem.java:25)
      file:///D:/workspace/zipfs/nosuchfile.zip
      ========================================

      My test code is below:
      ========================================
      import static TestUtils.TestTasks.*;
      import java.nio.file.FileSystems;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      import java.util.*;
      import com.sun.nio.zipfs.ZipFileSystem;

      // Basic newFileSystem test for zip file
      // Test environment variable: createNew
      public class ZipfsNewFileSystem {

      private static final String nonExistentFile = "nosuchfile.zip";

      public static void main(String[] args) throws Exception {

              Path file = Paths.get(nonExistentFile);
      Files.deleteIfExists(Paths.get(nonExistentFile)) ;

              Map<String, String> env = new HashMap<String, String>();
              env.put("create", "true");
              file = Paths.get(nonExistentFile);
      try {
      System.out.println(file.toUri()) ;
      ZipFileSystem fs = (ZipFileSystem)FileSystems.newFileSystem(file.toUri(), env, null) ;
                  // close now so the zip file gets flushed
                  fs.close();
      if (!Files.deleteIfExists(Paths.get(nonExistentFile))) {
      throw new RuntimeException(nonExistentFile + "should have been created!");
      }
      } catch (Exception e) {
      e.printStackTrace() ;
      }

      }

      }
      =====================================

            Assignee:
            Xueming Shen
            Reporter:
            Patrick Zhang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: