bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/23004] New: gnu.java.nio.channels.FileChannelImpl finaliz


From: tromey at gcc dot gnu dot org
Subject: [Bug classpath/23004] New: gnu.java.nio.channels.FileChannelImpl finalize problem
Date: 18 Sep 2005 01:25:20 -0000

The original finalize method in class 

gnu.java.nio.channels.FileChannelImpl:



protected void finalize() throws IOException

{

   this.close();

}



If constructor of FileChannelImpl throws an exception, 

as used in java.io.RandomAccessFile:

   

    FileChannelImpl ch = new FileChannelImpl (fileName, fdmode);



this assignment is not completed. Anyway an object is already constructed by 
the VM and it have to be collected as no one refers it. Finalize method is 
invoked. Fd for the object has the initial value of -1 and closed flag in the 
super class AbstractInterruptibleChannel is false,

and here we are in the native implCloseChannel method where to close a file 
with a fd = -1. >>> java.io.IOException 



This tiny check is proposed to avoid the trouble



protected void finalize() throws IOException

{

   if(fd >= 0)

    this.close();

}

   
------- Additional Comments From from-classpath at savannah dot gnu dot org  
2005-06-22 11:17 -------
The mistake is right!

The specification says that:



"...Any exception thrown by the finalize method causes the finalization of this 
object to be halted, but is otherwise ignored."



...seems that the problem is in the VM...
------- Additional Comments From tromey at gcc dot gnu dot org  2005-09-18 
01:25 -------
This was fixed by this patch:

2005-09-11  Mark Wielaard  <address@hidden>

        * gnu/java/nio/channels/FileChannelImpl.java (finalize): Check whether
        fd != -1 before calling close().


-- 
           Summary: gnu.java.nio.channels.FileChannelImpl finalize problem
           Product: classpath
           Version: unspecified
            Status: RESOLVED
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: from-classpath at savannah dot gnu dot org
                CC: bug-classpath at gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23004




reply via email to

[Prev in Thread] Current Thread [Next in Thread]