JDK-8223151 : (zipfs) newFileSystem���() should not throw FileSystemAlreadyExistsException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 11,12,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2019-04-28
  • Updated: 2019-08-23
  • Resolved: 2019-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Related Reports
Duplicate :  
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 ----------

This duplicates 8223771

This duplicates 8223771

This is a bug in the zip file system provider. The newFileSystem(Path) methods should not throw FileSystemAlreadyExistsException.

Link to the documentation: https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/nio/file/spi/FileSystemProvider.html To reproduce the issue, run the attached test case: JDK 11 - Fail JDK 12 - Fail JDK 13 ea+ 17 - Fail Below is the output: a == b: false a: D:\Java7Workspace\Tests\out.zip, b: D:\Java7Workspace\Tests\out.zip Providers ==: true a == a2: false Exception in thread "main" java.nio.file.FileSystemAlreadyExistsException at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:105) at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:337) at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:286) at JI9060435.main(JI9060435.java:29)