Name: gm110360 Date: 02/21/2002
FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
FULL OPERATING SYSTEM VERSION :
glibc-2.2.4-13
Linux 2.4.7-10 #1 Thu Sep 6 17:21:28 EDT 2001 i686 unknown
Red Hat Linux release 7.2 (Enigma)
A DESCRIPTION OF THE PROBLEM :
I tested FileChannel preformance
and tried to invoke some methods in cycle
and found following exception in method
FileChannel.transferFrom(..).
The cycle number (when the exception occurs) is not the
same at each test running and there are often more
than one exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create file CopyNio.java, compile it, set classpath.
2. Write command to create very simple testing file
that contains only "a" character:
$ echo a>a
3. Write command:
$ java CopyNio a a.copied
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
Program should silently end with copy of "a"
file at "a.copied"
What happens:
Program prints exception at some iteration step (or more).
When I stopped the execution
(System.exit(-1) in catch phase), file "a.copied" exists,
but has zero length.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Cyclus: 959
java.io.IOException: Bad address
at sun.nio.ch.FileDispatcher.pwrite0(Native Method)
at sun.nio.ch.FileDispatcher.pwrite(FileDispatcher.java:46)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:96)
at sun.nio.ch.IOUtil.write(IOUtil.java:60)
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:397)
at sun.nio.ch.FileChannelImpl.transfer(FileChannelImpl.java:330)
at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:316)
at CopyNio.main(CopyNio.java:19)
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class CopyNio
{
public static void main(String[] args) throws IOException
{
for (int i = 0; i < 1000; i++)
{
FileInputStream fis = null;
FileOutputStream fos = null;
try
{
fis = new FileInputStream(new File(args[0]));
fos = new FileOutputStream(new File(args[1]));
FileChannel fic = fis.getChannel();
FileChannel foc = fos.getChannel();
foc.transferFrom(fic, 0L, fic.size());
//fic.transferTo(0L, fic.size(), foc);
}
catch (Exception e)
{
System.err.println("Cyclus: " + i);
e.printStackTrace();
}
finally
{
if (fis != null) fis.close();
if (fos != null) fos.close();
}
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
When I use commented line with transferTo(..) method,
it works without any error message.
(Review ID: 139664)
======================================================================