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

Files.createDirectory throws AccessDeniedException after Files.delete

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7u45
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Files.createDirectory sometimes throws AccessDeniedException when called right after Files.delete or Files.deleteIfExists on this directory. Parent directory has right access rights.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run attached program to reproduce. It does multiple successful loops then fails with AccessDeniedException.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Directory test_dir is getting created and removed in endless loop without errors.
      ACTUAL -
      After multiple successful loops program fails with AccessDeniedException.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.nio.file.AccessDeniedException: test_dir
      at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
      at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
      at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
      at sun.nio.fs.WindowsFileSystemProvider.createDirectory(WindowsFileSystemProvider.java:496)
      at java.nio.file.Files.createDirectory(Files.java:628)
      at Test.main(Test.java:19)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      public static void main(String[] args) throws IOException {
          Path p = new File("test_dir").toPath();
                                                                 
          for (;;) {
              Files.deleteIfExists(p);
                                                                 
              Files.createDirectory(p);
                                                                 
              System.out.println("OK");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I was able to workaround the problem by adding wait and retry like this

      try {
          Files.createDirectory(p);
      } catch (AccessDeniedException e) {
          Thread.sleep(10);
                                           
          Files.createDirectory(p);
      }

            dxu Dan Xu (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: