RFR: 8365807: (fs) Two-arg UnixFileAttributes.getIfExists should not use exception for control flow [v2]

Alan Bateman alanb at openjdk.org
Fri Aug 22 16:47:55 UTC 2025


On Fri, 22 Aug 2025 16:27:08 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> In the Unix implementation of `sun.nio.fs`, change
>> 
>> 1. `UnixFileAttributes.getIfExists(UnixPath,boolean)` to use the system call success status and `errno` for control flow; and
>> 2. `UnixFileAttributes.getIfExists(UnixPath)` to simply return `UnixFileAttributes.getIfExists(UnixPath,true)`.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8365807: Make all [f]stat*0 functions void; remove stat2

UnixFileAttributes.getIfExists is performance critical so this is why it the native method returns errno rather than throws. The suggestion is the new 2-arg getIfExits work the same way and only throw if the error is not ENOENT. My comment on void vs. int return is to point out the hazard when we have two styles, it's too easy to call the method that does not throw when an exception is expected. This lead to the suggestion to choose a naming convention to avoid mistakes.

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

PR Comment: https://git.openjdk.org/jdk/pull/26889#issuecomment-3214988601


More information about the nio-dev mailing list