RFR: 8365807: (fs) Two-arg UnixFileAttributes.getIfExists should not use exception for control flow
Alan Bateman
alanb at openjdk.org
Fri Aug 22 09:42:56 UTC 2025
On Thu, 21 Aug 2025 22:03:40 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)`.
src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java line 122:
> 120: UnixFileAttributes attrs = new UnixFileAttributes();
> 121: int flag = (followLinks) ? 0 : UnixConstants.AT_SYMLINK_NOFOLLOW;
> 122: UnixNativeDispatcher.fstatat(dfd, path, flag, attrs);
If dfd/path does not exist then won't this now return an unpopulated UnixFileAttributes?
I think my concern is that the changes create a bit of a hazard. Most UnixNativeDispatcher native methods throw if the syscall fails, a small number return the errno, now we have a native method that special cases ENOENT. I think we should try to limit it to two variants, one that throws, the other that returns errno, and establish some naming convention to reduce the possibility of mis-use. It would be good to audit out tests to make sure that every method exercises error cases.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26889#discussion_r2293236377
More information about the nio-dev
mailing list