JDK-6486606 : FileOutputStream ctor throws IOE rather than FNF; Also possible HANDLE leak (1.4.2)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2_09
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2006-10-26
  • Updated: 2011-07-04
  • Resolved: 2011-07-04
Related Reports
Duplicate :  
Relates :  
Description
The code
public static void copy(java.io.File src, java.io.File target) throws IOException{
    java.io.FileInputStream fin = new java.io.FileInputStream( src );
    try {
        java.io.FileOutputStream fout = new java.io.FileOutputStream( target );
        try {
            fin.getChannel().transferTo( 0, src.length(), fout.getChannel());
	} finally {
            fout.close();
        }
    } finally {
        fin.close();
    }
}

sporadically fails if the file "target" resides on a remote filesystem which is available through a SMB share.
The failure is twofold:
1. On the target SMB share files of size 0 are created (either correct size or 0 size!)
2. The target machine (Windows XP) runs out of FileDescriptors depending on the configured max value because files are not properly closed from a Windows viewpoint.

Comments
EVALUATION The 2048 handle limit mentioned appears related to CR 4189011 which has recently been fixed in a 1.4.2 revision release. I'm closing this issue out as a possible duplicate of that. If issue is still seen, please re-open/escalate this bug for 1.4.2
04-07-2011

EVALUATION -- After further investigation it appears the issue is that the 1.4.2 based application is hitting the limit of 2048 file descriptors. java.io.FileDescriptor uses a HANDLE rather than file descriptor since 5.0 so the problem is unlikely to occur with 5.0 or jdk6. It's not clear yet which component (or the application) is not closing a file.
13-11-2006

EVALUATION We need further information to evaluate this bug. In particular what does "sporadic" mean here? Does transferTo throw an exception? If so, it is possible to post a stack trace. If there isn't an exception then it is possible to attach truss output for when the problem occurs. Also, are there any errors in the SMB logs for when this problem occurs?
30-10-2006

WORK AROUND Give up on NIO and use plain FileInputStream.read(..) and FileOutputStream.write(..). For an application writing on remote filesystems this should be safe and fast enough.
26-10-2006