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

(zipfs) newFileSystem​() should not throw FileSystemAlreadyExistsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 11, 12, 13
    • core-libs
    • x86_64
    • windows_7

      A DESCRIPTION OF THE PROBLEM :
      It appears FileSystemProvider.newFileSystem(Path, Map) always creates new FileSystem objects, because:
      - It does not declare that it throws FileSystemAlreadyExistsException
      - FileSystemProvider.getFileSystem(URI) says that these file system will not be returned (there is also a typo "File systems created the" -> "File systems created **by** the")
      - ZipFileSystemProvider creates a new file system

      If this is the case it should be more clearly documented and the documentation should also explain the implications of this:
      What does this mean for FileSystemProviders which normally throw a FileSystemAlreadyExistsException when a FileSystem for the same resource is requested? Can the use of these multiple FileSystem instances corrupt the resource?


      ---------- BEGIN SOURCE ----------
      // Change this to a local zip file
      String pathToZip = "path/to/file.zip";
      URI uri = URI.create("jar:file:/" + pathToZip + "!/");
      Path path = Paths.get(pathToZip);

      FileSystem a = FileSystems.newFileSystem(path, null);
      FileSystem b = FileSystems.newFileSystem(uri, Collections.emptyMap());

      System.out.println("a == b: " + (a == b));
      System.out.println("a: " + a + ", b: " + b);
      System.out.println("Providers ==: " + (a.provider() == b.provider()));

      // Creates second FileSystem for the same resource
      FileSystem a2 = FileSystems.newFileSystem(path, null);
      System.out.println("a == a2: " + (a == a2));

      // Throws FileSystemAlreadyExistsException, as expected
      FileSystem b2 = FileSystems.newFileSystem(uri, Collections.emptyMap());
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: