United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5056395 : nio does not seem to work with Linux kernel 2.6.4 (and probably above)

Details
Type:
Bug
Submit Date:
2004-06-02
Status:
Resolved
Updated Date:
2004-11-05
Project Name:
JDK
Resolved Date:
2004-06-10
Component:
core-libs
OS:
linux,linux_suse_sles_8
Sub-Component:
java.nio
CPU:
x86
Priority:
P1
Resolution:
Fixed
Affected Versions:
1.4.2,1.4.2_04,1.4.2_07,1.4.2_21
Fixed Versions:
5.0 (b56)

Related Reports
Backport:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
Apparently nio does not really like to work here:-(  I tested this on SuSE 9.1pro (with stock kernel) but we had problem reports from a Mandrake 10 user (with 2.6.* kernel too). 

Thanks,
-- Marco


marco@linux:/tmp> cat FileCopyTest.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class FileCopyTest {

    public static void main(String[] args) {
        File a = new File("/tmp/a");
        File b = new File("/tmp/b");

        copyFile(a, b);
    } // end of main()

    public static void copyFile(File source, File dest){
        try {
            FileChannel in = new FileInputStream(source).getChannel();
            if(!dest.getParentFile().exists()) dest.getParentFile().mkdirs();
            FileChannel out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
            in.close();
            out.close();
        }
        catch ( IOException e ) {
            e.printStackTrace();
        }
    }
}
marco@linux:/tmp> cp -p ~/snapshot1.png /tmp/a
marco@linux:/tmp> java FileCopyTest
java.io.IOException: Invalid argument
        at sun.nio.ch.FileChannelImpl.transferTo0(Native Method)
        at sun.nio.ch.FileChannelImpl.transferToDirectly(FileChannelImpl.java:392)
        at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:487)
        at FileCopyTest.copyFile(FileCopyTest.java:21)
        at FileCopyTest.main(FileCopyTest.java:13)
marco@linux:/tmp> type java
java is hashed (/usr/lib/java/bin/java)
marco@linux:/tmp> java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
marco@linux:/tmp> ~/Creator/java/bin/java -version
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
marco@linux:/tmp> ~/Creator/java/bin/java FileCopyTest
java.io.IOException: Invalid argument
        at sun.nio.ch.FileChannelImpl.transferTo0(Native Method)
        at sun.nio.ch.FileChannelImpl.transferToDirectly(FileChannelImpl.java:392)
        at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:487)
        at FileCopyTest.copyFile(FileCopyTest.java:21)
        at FileCopyTest.main(FileCopyTest.java:13)
marco@linux:/tmp> uname -a
Linux linux 2.6.4-54.5-bigsmp #1 SMP Fri May 7 21:54:56 UTC 2004 i686 i686 i386 GNU/Linux
marco@linux:/tmp> cat /etc/SuSE-release
SuSE Linux 9.1 (i586)
VERSION = 9.1

###@###.### 2004-06-02

                                    

Comments
WORK AROUND

You could try to find all the places which use nio and replace them with the original io mechanisms.  But I don't think that's really a workaround.
###@###.### 2004-06-02
                                     
2004-06-02
EVALUATION

The same mechanism used to detect if transfers on pipes is supported has been extended to try and detect if file to file transfer is supported by sendfile. When sendfile does not support it then the file is mapped and copied over by more conventional means.
###@###.### 2004-06-07
                                     
2004-06-07
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger-rc

FIXED IN:
tiger-rc

INTEGRATED IN:
tiger-b56
tiger-rc


                                     
2004-09-19



Hardware and Software, Engineered to Work Together