diff --git a/src/share/classes/java/nio/file/Files.java b/src/share/classes/java/nio/file/Files.java index 5c8d8be171a7028affb508c6dd94f57c41cfef31..012118c60f6d07925b99de3cfa7a40bb8c10b7c6 100644 --- a/src/share/classes/java/nio/file/Files.java +++ b/src/share/classes/java/nio/file/Files.java @@ -752,9 +752,12 @@ public final class Files { } if (parent == null) { // unable to find existing parent - if (se != null) + if (se == null) { + throw new FileSystemException(dir.toString(), null, + "Unable to determine if root directory exists"); + } else { throw se; - throw new IOException("Root directory does not exist"); + } } // create directories diff --git a/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java index 1f4f4ace844f83b8246b98235735b167834dc1f7..182a57b94c2131fe9efa7cca17f37878b8b59e9e 100644 --- a/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java +++ b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java @@ -375,11 +375,12 @@ public abstract class UnixFileSystemProvider UnixPath dir = UnixPath.toUnixPath(obj); dir.checkWrite(); - int mode = UnixFileModeAttribute - .toUnixMode(UnixFileModeAttribute.ALL_PERMISSIONS, attrs); + int mode = UnixFileModeAttribute.toUnixMode(UnixFileModeAttribute.ALL_PERMISSIONS, attrs); try { mkdir(dir, mode); } catch (UnixException x) { + if (x.errno() == EISDIR) + throw new FileAlreadyExistsException(dir.toString()); x.rethrowAsIOException(dir); } } diff --git a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java index 727cca38d7523e38d3f72d7861a7ed83b9502784..bd5f890d3ab4bf8900baff102c69a1b25870983c 100644 --- a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java +++ b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java @@ -493,6 +493,14 @@ public class WindowsFileSystemProvider try { CreateDirectory(dir.getPathForWin32Calls(), sd.address()); } catch (WindowsException x) { + // convert ERROR_ACCESS_DENIED to FileAlreadyExistsException if we can + // verify that the directory exists + if (x.lastError() == ERROR_ACCESS_DENIED) { + try { + if (WindowsFileAttributes.get(dir, false).isDirectory()) + throw new FileAlreadyExistsException(dir.toString()); + } catch (WindowsException ignore) { } + } x.rethrowAsIOException(dir); } finally { sd.release(); diff --git a/test/java/nio/file/Files/Misc.java b/test/java/nio/file/Files/Misc.java index 191a4fa2807963b2731bf81d2b0ab48e3fe5b0c3..5826d551d0b301debe6de09d7d973a2e6deaf0e6 100644 --- a/test/java/nio/file/Files/Misc.java +++ b/test/java/nio/file/Files/Misc.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4313887 6838333 8005566 + * @bug 4313887 6838333 8005566 8032220 * @summary Unit test for miscellenous methods in java.nio.file.Files * @library .. */ @@ -76,6 +76,11 @@ public class Misc { createDirectories(file.resolve("y")); throw new RuntimeException("failure expected"); } catch (IOException x) { } + + // the root directory always exists + Path root = Paths.get("/"); + Files.createDirectories(root); + Files.createDirectories(root.toAbsolutePath()); } /**