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

Race condition in File.mkdirs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      Apparently java.io.File.mkdirs has a race condition that causes it to fail
      if a parent directory is created by a different thread.

              if (mkdir()) {
                  return true;
              }
      // step one
              File canonFile = null;
              try {
                  canonFile = getCanonicalFile();
              } catch (IOException e) {
                  return false;
              }
              String parent = canonFile.getParent();
              return (parent != null) &&
                     (new File(parent, fs.prefixLength(parent)).mkdirs() &&
      // step two
                                          canonFile.mkdir());

      If the parent file is created between step one and step two, the method
      will fail to create the child.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ahe Peter Ahe
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: