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: 6429910
Votes 0
Synopsis (fc) FileChannel.lock() IOException: Bad file number, not AsynchronousCloseException
Category java:classes_nio
Reported Against
Release Fixed 7(b57)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6209658
Submit Date 24-MAY-2006
Description
FULL PRODUCT VERSION :
Both:

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
SunOS goldtpus7 5.8 Generic_108528-23 sun4u sparc SUNW,Sun-Fire-280R

A DESCRIPTION OF THE PROBLEM :
Coding timeout for FileChannel.lock() by closing the channel from a timer thread. Get

java.io.IOException: Bad file number
        at sun.nio.ch.FileChannelImpl.lock0(Native Method)
        at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:750)
        at java.nio.channels.FileChannel.lock(FileChannel.java:865)

Instead of AsynchronousCloseException

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the applied test.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
test passed
ACTUAL -
test failed: wrong exception class
java.io.IOException: Bad file number
        at sun.nio.ch.FileChannelImpl.lock0(Native Method)
        at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:750)
        at java.nio.channels.FileChannel.lock(FileChannel.java:865)
        at Simul$Waiter.run(Simul.java:14)
        at java.lang.Thread.run(Thread.java:534)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.nio.channels.*;

public class Simul
{
    static FileChannel m_channel;

    static class Waiter implements Runnable
    {
        public void run()
        {
            try
            {
                m_channel.lock();
            }
            catch( AsynchronousCloseException ace )
            {
                System.out.println( "test passed" );
                return;
            }
            catch( IOException ioe )
            {
                System.out.println( "test failed: wrong exception class" );
                ioe.printStackTrace();
                return;
            }
            System.out.println( "test failed\nwe were blocked until " +
                    "the other jvm released the lock\n" +
                    "are we on windows? this test was for Solaris!" );
        }
    }
    public static void main( final String[] args )
    {
        try
        {
            if ( args.length > 0 )
            {
                /* we just lock the file for 5 seconds */
                final FileOutputStream fos = new FileOutputStream( args[0] );
                final FileChannel channel = fos.getChannel();
                channel.lock();
                Thread.sleep( 5000l );
            }
            else
            {
                final File currDir = new File( "." );
                final File playFile =
                        File.createTempFile( "aaa_", ".txt", currDir );

                final String playPath = playFile.getCanonicalPath();
                final Runtime runtime = Runtime.getRuntime();
                final String execArgs[] = new String[]
                {
                    "java",
                    "-cp",
                    ".",
                    Simul.class.getName(),
                    playPath,
                };

                final Process me2 = runtime.exec( execArgs );

                /* give the other jvm time to start up */
                Thread.sleep( 1000l );
                try
                {
                    me2.exitValue();
                    System.out.println( "failed to launch second jvm" );
                }
                catch( IllegalThreadStateException itse )
                {
                    final FileOutputStream fos = new FileOutputStream( playFile );
                    m_channel = fos.getChannel();
                    final Runnable waiter = new Waiter();
                    final Thread t = new Thread( waiter, "waiter" );
                    t.start();
                    /* give the waiter time to start */
                    Thread.sleep( 500l );
                    fos.close();
                    m_channel.close();
                }
            }
        }
        catch( Throwable t )
        {
            t.printStackTrace();
        }
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Catch IOException
and treat it as
AsynchronousCloseException
Posted Date : 2006-05-24 15:45:28.0
Work Around
N/A
Evaluation
Yes, we need to handle this case and throw AsynchronousCloseException as specified. The bug arrived too late for Mustang so we have to defer it to Dolphin.
Posted Date : 2006-05-24 16:08:52.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang