RFR: 8365626: (fs) Improve handling of broken links in Files.isSameFile() (win)

Alan Bateman alanb at openjdk.org
Fri Sep 5 12:46:11 UTC 2025


On Thu, 4 Sep 2025 15:32:34 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/windows/classes/sun/nio/fs/WindowsFileAttributes.java line 477:
>> 
>>> 475:     @Override
>>> 476:     public int hashCode() {
>>> 477:         return volSerialNumber + fileIndexHigh + fileIndexLow;
>> 
>> Should we combine these values with something more complex than a sum to reduce potential collisions?
>
>> Should we combine these values with something more complex than a sum to reduce potential collisions?
> 
> This method is there mainly to silence the compilation warning about overriding `equals` while not overriding `hashCode`. Overriding `equals` was necessary for detecting a file system loop (cycle). This class is package scope and I don't think that `hashCode` will ever be used.

Methods such as Files.readAttributes will return a WindowsFileAttributes object can't have equals accessing the file system. The API docs don't specify the equality of XXFileAttributes. If specified it would likely be specified based on the value of the snapshot, not just the file key.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27079#discussion_r2324994820


More information about the nio-dev mailing list