harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paulex Yang (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-479) java.io.FileInputStream and FileOutputStream might cause Finalizer thread suspending
Date Fri, 19 May 2006 05:13:29 GMT
java.io.FileInputStream and FileOutputStream might cause Finalizer thread suspending

         Key: HARMONY-479
         URL: http://issues.apache.org/jira/browse/HARMONY-479
     Project: Harmony
        Type: Bug

  Components: Classlib  
    Reporter: Paulex Yang

If one FileInputStream instance is not constructed properly, say, the given file doesn't exist,
the constructor will throw exception but the FileInputStream instance is still necessary to
be garbage collected, and the spec of FileInputStream's finalize() method requires that close()
must be invoked, but the current implementation of FileInputStream.close()(as below) will
causes NullPointerException in Finalizer thread because channel field has not been initialized

    public void close() throws IOException {
            synchronized (channel) {
                synchronized (this) {
                    if (channel.isOpen() && fd.descriptor >= 0) {
                    fd.descriptor = -1;

This issue applies to FileOutputStream, too. Test case below can reproduce this issue only
in debugger, because it is not easy to get the handle of Finalizer thread. Debugging the test
case to the statement following the System.gc(), the debugger will show that the Finalizer
thread is suspended due to NullPointerException.

public class FileInputStreamTest {
    public static void main(String[] args) throws Exception{
        FileInputStream is = null;
            is = new FileInputStream(new File("nonexist"));
        }catch(Exception e){

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message