Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4081750
Votes 0
Synopsis java.io.RandomAccessFile: Add a finalize method
Category java:classes_io
Reported Against 1.1.4 , 1.4.2
Release Fixed
State 11-Closed, Will Not Fix, request for enhancement
Priority: 3-Medium
Related Bugs 4192722 , 4777499 , 4919795 , 4099999
Submit Date 25-SEP-1997
Description




I know one isn't supposed to rely on files being
closed by themselves.

But, RandomAccessFile should have a finalize()
method which closes the file descriptor, the same
way that FileOutputStream and friends do.
======================================================================
Work Around





======================================================================
Evaluation
As the submitter seems to realize, finalization is not a reliable way to close
open files.  At best it is a flaky method of last resort that shouldn't be
relied upon.  Files should be opened within try/finally blocks that take care
to ensure that they are closed.  Having said that, adding a finalize() method
to RandomAccessFile is something to consider for the next feature release.

--   xxxxx@xxxxx   10/6/1997

In light of 4099999, I'm not going to do this.  Using a finalizer to close an
open file is just a bad idea, especially since it closes the underlying
FileDescriptor, which may be in use by some other stream.

--   xxxxx@xxxxx   1/7/1998

There is yet another reason not to add a finalize() method to RandomAccessFile:
It would impose a significant performance penalty upon programs that need to
open many files quickly.  The File{In,Out}putStream classes, which do have
finalizers, are unusable by such programs due to the strain that they place
upon the garbage collector.  If we add a finalizer to RandomAccessFile then we
will adversely affect the performance of existing programs which rely upon the
fact that RandomAccessFile has no finalizer.

--   xxxxx@xxxxx   2003/2/11
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang