--- a/jdk/src/share/classes/sun/nio/fs/AbstractPath.java Mon Jan 18 14:56:06 2010 +0000
+++ b/jdk/src/share/classes/sun/nio/fs/AbstractPath.java Mon Jan 18 15:21:34 2010 +0000
@@ -256,8 +256,8 @@
}
if (option == null)
throw new NullPointerException();
- throw new IllegalArgumentException("'" + option +
- "' is not a valid copy option");
+ throw new UnsupportedOperationException("'" + option +
+ "' is not a recognized copy option");
}
return result;
}
@@ -279,9 +279,21 @@
if (attrs.isSymbolicLink())
throw new IOException("Copying of symbolic links not supported");
- // delete target file
- if (opts.replaceExisting)
- target.deleteIfExists();
+ // check if target exists
+ boolean exists;
+ if (opts.replaceExisting) {
+ try {
+ target.deleteIfExists();
+ exists = false;
+ } catch (DirectoryNotEmptyException x) {
+ // let exception translate to FileAlreadyExistsException (6895012)
+ exists = true;
+ }
+ } else {
+ exists = target.exists();
+ }
+ if (exists)
+ throw new FileAlreadyExistsException(target.toString());
// create directory or file
if (attrs.isDirectory()) {
@@ -318,7 +330,7 @@
ReadableByteChannel rbc = newByteChannel();
try {
// open target file for writing
- SeekableByteChannel sbc = target.newByteChannel(CREATE, WRITE);
+ SeekableByteChannel sbc = target.newByteChannel(CREATE_NEW, WRITE);
// simple copy loop
try {