6978511: (file) Path.toRealPath should fail if not resolving links and file does not exist
authoralanb
Mon, 23 Aug 2010 17:11:07 +0100
changeset 6318 b279b6772e21
parent 6317 8046f5f96da1
child 6319 47d9b9e70f99
6978511: (file) Path.toRealPath should fail if not resolving links and file does not exist Reviewed-by: forax, chegar
jdk/src/solaris/classes/sun/nio/fs/UnixPath.java
jdk/test/java/nio/file/Path/Misc.java
--- a/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java	Mon Aug 23 16:27:56 2010 +0100
+++ b/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java	Mon Aug 23 17:11:07 2010 +0100
@@ -1141,6 +1141,13 @@
             }
             result = result.resolve(element);
         }
+
+        // check file exists (without following links)
+        try {
+            UnixFileAttributes.get(result, false);
+        } catch (UnixException x) {
+            x.rethrowAsIOException(result);
+        }
         return result;
     }
 
--- a/jdk/test/java/nio/file/Path/Misc.java	Mon Aug 23 16:27:56 2010 +0100
+++ b/jdk/test/java/nio/file/Path/Misc.java	Mon Aug 23 17:11:07 2010 +0100
@@ -261,6 +261,21 @@
         assertTrue(file.toRealPath(true).isSameFile(file.toRealPath(false)));
 
         /**
+         * Test: toRealPath should fail if file does not exist
+         */
+        Path doesNotExist = dir.resolve("DoesNotExist");
+        try {
+            doesNotExist.toRealPath(true);
+            throw new RuntimeException("IOException expected");
+        } catch (IOException expected) {
+        }
+        try {
+            doesNotExist.toRealPath(false);
+            throw new RuntimeException("IOException expected");
+        } catch (IOException expected) {
+        }
+
+        /**
          * Test: toRealPath(true) should resolve links
          */
         if (supportsLinks) {