IOException from sun.nio.fs.UnixUserPrincipals.lookupName
Jonathan Lu
luchsh at linux.vnet.ibm.com
Sun Nov 20 23:35:54 PST 2011
Hi nio-dev,
I got a exception from sun.nio.fs.UnixUserPrincipals.lookupName(), the
stack trace looks like
java.io.IOException: 12345!@#$%^&:
at sun.nio.fs.UnixUserPrincipals.lookupName(UnixUserPrincipals.java:148)
at sun.nio.fs.UnixUserPrincipals.lookupUser(UnixUserPrincipals.java:170)
at
sun.nio.fs.UnixFileSystem$LookupService$1.lookupPrincipalByName(UnixFileSystem.java:331)
The expected exception ought be UserPrincipalNotFoundException instead
of IOException, since my application was testing with a non-existing user.
Then I found following code piece from
solaris/native/sun/nio/fs/UnixNativeDispatcher.c:1005
if (res != 0 || p == NULL || p->pw_name == NULL ||
*(p->pw_name) == '\0') {
/* not found or error */
if (errno != 0 && errno != ENOENT)
throwUnixException(env, errno);
} else {
uid = p->pw_uid;
}
Seems the "throwUnixException(env, errno)" statement caused this
IOException, and the actual value of errno for my application is ESRCH
(3), which means "no such process".
As I understand, UnixException is thrown only when error occurs instead
of when user name is not found, right?
Since these checks are all about the result of getpwnam_r API, so I
searched the system manual and found,
The Linux manual says,
ERRORS
0 or ENOENT or ESRCH or EBADF or EPERM or ...
The given name or uid was not found.
The Solaris 11 manual even does not mention ENOENT!
So does anybody know why only ENOENT is checked here?
What about at least adding ESRCH to this check list as attached patch did?
Regards
- Jonathan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ESRCH_check.patch
Type: text/x-patch
Size: 612 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20111121/d4d42d32/ESRCH_check.patch
More information about the nio-dev
mailing list