Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4391178

java.io.File.createNewFile incorrectly throws IOException on "/" (Solaris)

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      rc1
    • CPU:
      sparc
    • OS:
      solaris_7
    • Verification:
      Verified

      Backports

        Description



        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
        ----------------------------------------------------------------------
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                mr Mark Reinhold
                Reporter:
                alssunw Als Als (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: