RFR: 8368156: java/nio/file/Files/IsSameFile.java failing (win)

Jaikiran Pai jpai at openjdk.org
Tue Sep 23 09:03:29 UTC 2025


On Tue, 23 Sep 2025 08:41:35 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> test/jdk/java/nio/file/Files/IsSameFile.java line 158:
>> 
>>> 156:         try (FileSystem zipfs = FileSystems.newFileSystem(b)) {
>>> 157:             list = new ArrayList<Arguments>();
>>> 158:             list.add(Arguments.of(false, a, zipfs.getPath(b.toString())));
>> 
>> Hello Brian, this returns a collection which contains a `Path` that is obtained from a `FileSystem` that gets closed before the `Path` is used in the test method. Looking at the specification of `FileSystem.getPath()` I don't see any text which states the behaviour of `Path` instances after the `FileSystem` has been closed. I think we would be relying on unspecified behaviour here. Would it be better to refactor this a bit so that the `FileSystem` gets closed after the test(s) are complete?
>
>> Hello Brian, this returns a collection which contains a `Path` that is obtained from a `FileSystem` that gets closed before the `Path` is used in the test method. Looking at the specification of `FileSystem.getPath()` I don't see any text which states the behaviour of `Path` instances after the `FileSystem` has been closed.
> 
> The FileSystem class description does specify: "Once closed, any further attempt to access objects in the file system cause ClosedFileSystemException to be thrown". I don't have time right now to check that the zip file system adheres to this.

Hello Alan,

> I don't have time right now to check that the zip file system adheres to this.

I did a quick check. Not all methods on `Path` returned by the ZIP filesystem, adhere to this specification. For example, `toURI()`, `toAbsolutePath()`, `relativize()` all return normally even after the ZIP file system is closed. Whereas, `toRealPath()` throws `ClosedFileSystemException`:


jshell> var fs = FileSystems.newFileSystem(java.net.URI.create("jar:file:///tmp/foo.jar"), Map.of())
fs ==> /tmp/foo.jar

jshell> var p = fs.getPath("/");
p ==> /

jshell> fs.close()

jshell> var _ = p.toAbsolutePath()
 ==> /

jshell> var _ = p.toUri()
 ==> jar:file:///tmp/foo.jar!/

jshell> var _ = p.relativize(p)
 ==> 

jshell> var _ = p.toRealPath()
|  Exception java.nio.file.ClosedFileSystemException
|        at ZipFileSystem.ensureOpen (ZipFileSystem.java:1843)
|        at ZipFileSystem.checkAccess (ZipFileSystem.java:584)
|        at ZipPath.checkAccess (ZipPath.java:885)
|        at ZipPath.toRealPath (ZipPath.java:176)
|        at ZipPath.toRealPath (ZipPath.java:56)
|        at do_it$Aux (#4:1)
|        at (#4:1)

I haven't yet checked other object types returned by the ZipFileSystem, but it does look like it will need some updates to adhere to the specification. I'll take a deeper look and track this separately.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27440#discussion_r2371637360


More information about the nio-dev mailing list