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

(fs) Files.move() throws DirectoryNotEmptyException pointing to wrong directory (win)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • tbd
    • 7u25
    • core-libs

      FULL PRODUCT VERSION :
      java version " 1.7.0_25 "
      Java(TM) SE Runtime Environment (build 1.7.0_25-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Files.move() is throwing a misleading error message complaining that the target path is not empty when in fact the target path does not exist at all.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run testcase

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1. The DirectoryNotEmptyException exception message should point to the source directory, since the fact that it is not empty is preventing the move operation.

      2. The Javadoc should be updated to indicate that DirectoryNotEmptyException may be thrown if the source directory is not empty and resides on a different file-system than target.
      ACTUAL -
      1. DirectoryNotEmptyException thrown for a condition that is not mentioned in the method specification.
      2. DirectoryNotEmptyException message is incorrect, indicating that something is wrong with the target path when in fact the problem is with the source path.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread " main " java.nio.file.DirectoryNotEmptyException: d:\foobar
      at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:456)
      at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:286)
      at java.nio.file.Files.move(Files.java:1345)
      at movetestcase.MoveTestcase.main(MoveTestcase.java:17)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package movetestcase;

      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.nio.file.Paths;

      public class MoveTestcase {

          public static void main(String[] args) throws IOException {
              Path source = Files.createDirectories(Paths.get( " c:/foobar/subdir " ));
              source = source.getParent();
              Path target = Paths.get( " d:/foobar " );
              // Throws DirectoryNotEmptyException: d:/foobar but actually the problem
              // is that the source directory is non-empty and resides on a different
              // drive than the target directory.
              Files.move(source, target);
          }
      }
      ---------- END SOURCE ----------

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: