RFR: 8365807: (fs) Two-arg UnixFileAttributes.getIfExists should not use exception for control flow [v2]
Alan Bateman
alanb at openjdk.org
Sun Aug 24 06:57:55 UTC 2025
On Fri, 22 Aug 2025 16:51:01 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> > UnixFileAttributes.getIfExists is performance critical so this is why it the native method returns errno rather than throws.
>
> So the `stat0` and `fstatat0` methods should revert to returning `errno`.
Right, these are private. UnixNativeDispatcher will define stat and fstatat that throw UnixException for all errors. The variant of stat that doesn't thrown is currently named stat2, I assumed we would have fstatat2 too. We can choose better names of course. It means that 2-arg getIfExists won't need to rely on exceptions for control flow, and means the 1-arg getIfExists can be re-implemented to use to use the 2-arg getIfExists. It also avoids the hazard of changing an existing method to not throw when the naming and existing usages assume an exception for all error cases.
Longer term we could get rid of all the exception throwing in the JNI functions and have them return -errno. This is how some of the new syscalls work anyway as the negative range isn't otherwise used. I'm not suggesting we do this now. If this code is eventually replaced to use FFM then it would be minimally disruptive to the file system provider implementation.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26889#issuecomment-3217889918
More information about the nio-dev
mailing list