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

(fs) Files.move does not throw DirectoryNotEmptyException when source is non-empty

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P3
    • tbd
    • 7, 15
    • core-libs
    • None
    • linux, os_x, windows

    Description

      “ DirectoryNotEmptyException - the REPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory, or the source is a non-empty directory containing entries that would be required to be moved”

      Observation :
      ------------------
      When the code tries to move the file from a source to a non-empty target the desired exception is thrown.
      But when the source is non-empty directory but target is empty directory the desired exception is not thrown, As I understand it should throw the desired exception in this case too?

      Platform : Windows, Linux
      JDK used : JDK-15 (ea -26)

      Please find the attached code snippet, where “source” directory is non –empty but the “target5” is empty.

      ======================================================================
      public class MoveFilesTest {

          public static void main(String[] args)
          {
              new MoveFilesTest().runtTest();
          }

          private void runtTest() {

              Path path = Paths.get("/scratch/kganapur").resolve("source");
              Path path1 = Paths.get("/scratch/kganapur").resolve("target5");

              try {
                  System.out.println("The paths are " + path + " " + path1);
                  Files.move(path, path1, StandardCopyOption.REPLACE_EXISTING);
                  System.out.println("FAILED: DirectoryNotEmptyException was NOT " +
                          "thrown");
              } catch (DirectoryNotEmptyException expected) {
                  System.out.println("expected DNEmpty Ex ");
              } catch (IOException ioe) {
                  // permissible in place of DirectoryNotEmptyException
                  System.out.println("WARNING: " + ioe);
              }
              System.out.println("OKAY");
          }
      }

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              kganapureddy Krushnareddy Ganapureddy
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: