-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8365807: (fs) Two-arg UnixFileAttributes.getIfExists should not use exception for control flow #26889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…xception for control flow
👋 Welcome back bpb! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
Webrevs
|
@@ -130,7 +119,7 @@ static UnixFileAttributes get(int dfd, UnixPath path, boolean followLinks) | |||
{ | |||
UnixFileAttributes attrs = new UnixFileAttributes(); | |||
int flag = (followLinks) ? 0 : UnixConstants.AT_SYMLINK_NOFOLLOW; | |||
UnixNativeDispatcher.fstatat(dfd, path.asByteArray(), flag, attrs); | |||
UnixNativeDispatcher.fstatat(dfd, path, flag, attrs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was intended to address this comment
a version that doesn't use exceptions for control flow,
but I think I misinterpreted that. I'll reassess the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 7ea1b08:
- Change
fstatat0
andstat0
to throw instead of returningerrno
. - Remove the
stat2
method. - Change calling code to handle the changes.
Now all ?stat{at}0
functions are void, expressing errors via UnixException
.
All UnixNativeDispatcher
methods are now void
except:
jbytearray getcwd, getgrid, getgrnam, getpwnam, getpwuid, readdir, realpath, strerror
jint access, dup, fgetxattr, flistxattr, getlinelen, openat, read, write
jlong fdopendir, opendir
All these functions return a "useful" value, except access
which returns errno
. It would be a little disruptive to change access
to throw instead of returning errno
as there are a number of usages like
return access(path, mode) == 0;
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. |
So the |
As there are only a couple of methods that return |
In the Unix implementation of
sun.nio.fs
, changeUnixFileAttributes.getIfExists(UnixPath,boolean)
to use the system call success status anderrno
for control flow; andUnixFileAttributes.getIfExists(UnixPath)
to simply returnUnixFileAttributes.getIfExists(UnixPath,true)
.Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26889/head:pull/26889
$ git checkout pull/26889
Update a local copy of the PR:
$ git checkout pull/26889
$ git pull https://git.openjdk.org/jdk.git pull/26889/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26889
View PR using the GUI difftool:
$ git pr show -t 26889
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26889.diff
Using Webrev
Link to Webrev Comment