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

Brian Burkhalter bpb at openjdk.org
Thu Sep 18 16:33:54 UTC 2025


On Thu, 18 Sep 2025 14:24:52 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8365626: Cleanup
>
> src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java line 471:
> 
>> 469:                 try {
>> 470:                     h = path.openForReadAttributeAccess(false);
>> 471:                 } catch (WindowsException x) {
> 
> I think you'll need to init h to INVALID_HANDLE_VALUE here or when WindowsException is thrown, otherwise there is a risk that it will be closed twice, assuming I'm reading it correctly.

I am probably missing something, but `h` is set to `INVALID_HANDLE_VALUE` before the while-loop is entered and reset to that value at line 486. It is set to a valid value at line 470 unless `openForReadAttributeAccess` throws an exception in which case it will be closed in the finally block. So it can only have a valid value between lines 478 and 484, inclusive. If there is a break or an exception in that line range, then `h` should be closed in the finally block. If there is an exception in the line range 490-491, then `h` will be `INVALID_HANDLE_VALUE` and would not be closed in the finally block.

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

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


More information about the nio-dev mailing list