RFR [8055421]: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

Ivan Gerasimov ivan.gerasimov at oracle.com
Fri Aug 22 20:59:29 UTC 2014

How about another approach?
If we face EINTR, we can try to fallback to restartable close():

Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, 
jlong stream)
     int res, fd;
     FILE* fp = jlong_to_ptr(stream);

     fd = fileno(fp);
     res = fclose(fp);
     if (res == EOF) {
         if (errno == EINTR) {
             if (fd == -1) {
                 errno = EBADF;
             } else {
                 RESTARTABLE(close(fd), res);
         if (res != 0) {
             throwUnixException(env, errno);

It's strange we have to do this, though.
I'm pretty sure it was not meant to be used this way.
I would think that fclose handles EINTR internally, but the 
documentation says nothing about it.

Sincerely yours,

More information about the nio-dev mailing list