-
Bug
-
Resolution: Fixed
-
P2
-
1.3.1, 1.4.0
-
rc1
-
sparc
-
solaris_7
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2038769 | 1.4.0 | Mark Reinhold | P2 | Closed | Fixed | beta |
Name: asR10013 Date: 11/21/2000
The following sample code and output show incorrect behavior of
method java.io.File.createNewFile under Solaris.
API specificaion reads:
public boolean createNewFile() throws IOException
Atomically creates a new, empty file named by this abstract pathname if
and only if a file with this name does not yet exist. The check for the
existence of the file and the creation of the file if it does not exist are a
single operation that is atomic with respect to all other filesystem activities
that might affect the file. This method, in combination with the
deleteOnExit() method, can therefore serve as the basis for a simple but
reliable cooperative file-locking protocol.
Returns:
true if the named file does not exist and was successfully created;
false if the named file already exists
Throws:
IOException - If an I/O error occurred
SecurityException - If a security manager exists and its
SecurityManager.checkWrite(java.io.FileDescriptor) method
denies write access to the file
---------------------- end of citation -------------------------------
There is a difference in behavior between linux and solaris jvms.
Solaris jdk1.3.1-b08 incorrectly throws IOException for filename '/'
whereas this file exists and method should return false.
The problem is reproducible on:
* solaris jdk1.3.1-b08
* solaris jdk1.4.0-b40
JCK1.3a test api/java_io/File/OtherMethodsTests.html#createNewFile
gives incorrect result, because of this bug.
------------------------ test.java -----------------------------------
import java.io.*;
class test {
public static void main(String args[]) {
File f[] = { new File(""), new File("/"), new File("/tmp") };
for (int i=0; i<f.length; i++) {
System.out.println("Checking filename '"+(f[i]).getPath()+"'");
try {
System.out.println("result: "+(f[i]).createNewFile());
} catch (IOException e) {
System.out.println(e);
}
}
}
}
---------------------- linux output ----------------------------------
$ java -version
java version "1.3.1beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1beta-b08)
Java HotSpot(TM) Client VM (build 1.3.1beta-b08, mixed mode)
$ java test
Checking filename ''
java.io.IOException: No such file or directory
Checking filename '/'
result: false
Checking filename '/tmp'
result: false
--------------------- solaris output ---------------------------------
$ java -version
java version "1.3.1beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1beta-b08)
Java HotSpot(TM) Client VM (build 1.3.1beta-b08, mixed mode)
$ java test
Checking filename ''
java.io.IOException: No such file or directory
Checking filename '/'
java.io.IOException: Invalid argument
Checking filename '/tmp'
result: false
----------------------------------------------------------------------
======================================================================
- backported by
-
JDK-2038769 java.io.File.createNewFile incorrectly throws IOException on "/" (Solaris)
-
- Closed
-