JDK-4136096 : Temp file doesn't work properly with File.renameTo() on Solaris
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1998-05-07
  • Updated: 1998-05-07
  • Resolved: 1998-05-07
Related Reports
Duplicate :  
Relates :  
Description
File.renameTo() doesn't behave the same way on Win32 and Solaris.
The following simple test shows the problem.

import java.io.*;

public class test {
    public static void main(String argv[]) throws IOException {
        File tmpFile = File.createTempFile("tmp");
        System.out.println(tmpFile);
        File inputFile = new File("junk");
        System.out.println(inputFile);
	// another bug here, see 4017593
	// win32 needs a delete() before rename
        inputFile.delete();
        System.out.println(tmpFile.renameTo(inputFile));
    }
}


On Solaris, if property java.io.tmpdir is set to another mounted
filesystem other than the current one , or the user specifies 
that explicitly when creating the tmpFile, the renameTo() call
will fail.

On Win32, the test works as expected.

Comments
EVALUATION Not a bug. The renameTo method is not specified to copy files across filesystems. In general a program must check the return value and be prepared to copy the file itself if that's what's required. -- mr@eng 5/7/1998
07-05-1998