RFR: 8280881: (fs) UnixNativeDispatcher.close0 may throw UnixException [v4]

Alan Bateman alanb at openjdk.java.net
Fri Feb 25 15:48:54 UTC 2022


On Thu, 24 Feb 2022 23:23:46 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Re-specify `sun.nio.fs.UnixNativeDispatcher.close0()` to throw `sun.nio.fs.UnixException` and modify callers either to ignore it or to rethrow it as an `IOException`, as appropriate.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8280881: s/close(fd,null)/close(fd, e-> null)/

This looks much cleaner but it may be a bit overboard in a few places where there is an exception and the cleanup has to close and also fails.

src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java line 74:

> 72:         } catch (UnixException x) {
> 73:             throw UnixNativeDispatcher.close(ifd,
> 74:                 new IOException(x.errorString()), y -> y.asIOException(null));

The most likely cause of socketpair failing here would be resources or out of file descriptors. When that happens then it's probably not interesting to also try to report the failure of inotify close. So I think this close can be close(ifd, e-> null) too.

src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java line 189:

> 187:                 if (sfd >= 0) {
> 188:                     source.getFileSystem().copyNonPosixAttributes(sfd, dfd);
> 189:                     close(sfd, x -> x.asIOException(source));

This is the source fd so it's reading. It's not wrong to have it throw IOException, just a bit consistent to the other places where the exception is ignored.

src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java line 443:

> 441:             if (dfd2 != -1) {
> 442:                 ioe = UnixNativeDispatcher.close(dfd2, ioe,
> 443:                     z -> z.asIOException(dir));

It's not clear to me that the closing of dfd1 and dfd2 are interesting here, maybe they should be e -> null too.

src/java.base/unix/classes/sun/nio/fs/UnixSecureDirectoryStream.java line 130:

> 128:                     ioe = UnixNativeDispatcher.close(newdfd1, ioe,
> 129:                         z -> z.asIOException(file));
> 130:                 }

Same as UnixFileSystemProvider, I don't think the errors from closing newfd1 and newfd2 are useful here.

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

PR: https://git.openjdk.java.net/jdk/pull/7467


More information about the nio-dev mailing list