8201407: Files.move throws DirectoryNonEmptyException when moving directory across file system

Brian Burkhalter brian.burkhalter at oracle.com
Thu May 10 23:26:31 UTC 2018


https://bugs.openjdk.java.net/browse/JDK-8201407

On Unix, when attempting to move a non-empty directory to a different file system, Files.move() fails with a DirectoryNotEmptyException when it tries to delete the non-empty source directory after copying the top level directory only. The operative part of the specification of Files.move() is:

"When invoked to move a directory that is not empty then the directory is moved if it does not require moving the entries in the directory. For example, renaming a directory on the same FileStore will usually not require moving the entries in the directory. When moving a directory requires that its entries be moved then this method fails (by throwing an IOException).”

Although the DirectoryNotEmptyException is an IOException, it is not clearly specified that one will be thrown when attempting to move a non-empty source directory to a different file system. Also this situation is not detected in the code as early as it could be. A partial (no Windows change, no tests) fix is here:

http://cr.openjdk.java.net/~bpb/8201407/webrev.00/

If this looks like the correct thing to do, then I will file a CSR, develop an analogous Windows fix, and add tests.

Thanks,

Brian


More information about the nio-dev mailing list