RFR 8080225: FileInputStream cleanup should be improved

Roger Riggs Roger.Riggs at Oracle.com
Thu Oct 12 16:53:02 UTC 2017

Hi Alan,

On 10/12/2017 8:35 AM, Alan Bateman wrote:
> On 04/10/2017 15:35, Roger Riggs wrote:
>> Hi Mandy,
>> Updated the webrev in place:
>> http://cr.openjdk.java.net/~rriggs/webrev-fis-cleanup-8080225/
> I skimmed the latest webrev.
> The @apiNote in FIS is copied from FOS so it needs 
> s/FileOutputStream/FileInputStream/.
> I assume in FIS that we should skip registerCleanup when the fd is 
> FileDescriptor.in, ditto in FOS and RAF where we shouldn't register 
> for cleanup when the fd is one of the standard streams. Alternatively 
> handle this in FileDescriptor.
The FileDescriptors for in, out, err are held in static fields and 
should never be only phantom reachable.
The registration of cleanup handlers only occurs when opening files, not 
for constructors that accept a FileDescriptor.  So there will be no 
cleanup registrations for fd 0,1,2. (unless I'm missing a case)

> I'm curious why registerCleaner invoke clears and create a new 
> cleanup. There are cases where we create a FileDescriptor and set the 
> fd or handle lazily but these won't be registered until set.
Just an abundance of caution, currently there are no calls with set(-1) 
but if there were the
cleaner should be reset to avoid closing a stale fd at some future time.

Thanks, Roger
> Otherwise I think this looks quite good.
> -Alan

More information about the core-libs-dev mailing list