RFR 8080225: FileInputStream cleanup should be improved

Roger Riggs Roger.Riggs at Oracle.com
Thu Oct 12 19:13:01 UTC 2017

Hi Mandy,

True in advertising, the FileDescriptor.close() method should be 
declared to throw IOException.

Cleanup via the Cleaner.clean() method can't throw a checked exception 
but the IOException can be
wrapped with UncheckedIOException that can be caught by Cleaner.clean() 
They can unwrap the exception as needed.

When invoked from the Cleaner thread,  all exceptions are ignored.
Perhaps that is a better place to log unexpected exceptions.


On 10/12/2017 2:00 PM, mandy chung wrote:
> On 10/4/17 7:35 AM, Roger Riggs wrote:
>> Updated the webrev in place:
>> http://cr.openjdk.java.net/~rriggs/webrev-fis-cleanup-8080225/
> Looks good.  One minor comment:
> 251 private static native void cleanupClose0(int fd);
> 75 Java_java_io_FileDescriptor_cleanupClose0(JNIEnv *env, jclass 
> fdClass, jint fd) {
> 76 if (close(fd) == -1) {
> 77 JNU_ThrowIOExceptionWithLastError(env, "close failed");
> 78 }
> 79 }
> The native implementation throws IOException when there is any error.
> Not directly related to this change: when there is any error in 
> closing FIS/FOS,  the exception will be ignored by the cleaner. I 
> wonder if we could enhance the Cleaner's diagnosability to log any 
> exception thrown; of course this is a separate RFE that might have 
> been considered.
> Mandy

More information about the core-libs-dev mailing list