RFR: 8154364: (fs) Files.isSameFile() throws NoSuchFileException with broken symbolic links [v8]

Alan Bateman alanb at openjdk.org
Sat Aug 16 07:32:15 UTC 2025


On Fri, 15 Aug 2025 20:43:41 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> This request proposes to broaden the definition of which paths are considered to be the same by `java.nio.file.Files.isSameFile()`. A new test is added to cover many comparisons.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8154364: Put changes to Misc.java in platform-specific blocks

src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java line 379:

> 377:         }
> 378:         return keys;
> 379:     }

I'm a bit puzzled as to why it looks at each element in the path. It should be possible to just enumerate the files of the sym links that exist, something like this

        var fileKeys = new HashSet<UnixFileKey>();
        while (path != null) {
            UnixFileAttributes attrs = UnixFileAttributes.getIfExists(path, false);
            if (attrs != null && attrs.isSymbolicLink()) {
                fileKeys.add(attrs.fileKey());
                path = (UnixPath) readSymbolicLink(path);
            } else {
                path = null;
            }
        }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26736#discussion_r2280292509


More information about the nio-dev mailing list