“ 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");
}
}
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");
}
}
- relates to
-
JDK-8204300 Files.move throws DirectoryNotEmptyException when moving directory across file system
-
- Closed
-