A similar issue as reported for Unix in JDK-8306882.
If one has these files
./dir/subdir
./aaa@ -> dir/subdir
./out.txt
then trying to get the real path of "aaa/../../out.txt" in jshell gives:
jshell> Path p = Path.of("aaa/../../out.txt")
p ==> aaa\..\..\out.txt
jshell> p.toRealPath()
| Exception java.nio.file.NoSuchFileException: C:\Users\out.txt
| at WindowsException.translateToIOException (WindowsException.java:85)
| at WindowsException.rethrowAsIOException (WindowsException.java:96)
| at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:288)
| at WindowsPath.toRealPath (WindowsPath.java:944)
| at WindowsPath.toRealPath (WindowsPath.java:42)
| at (#2:1)
jshell> p.toRealPath(LinkOption.NOFOLLOW_LINKS)
| Exception java.nio.file.NoSuchFileException: C:\Users\out.txt
| at WindowsException.translateToIOException (WindowsException.java:85)
| at WindowsException.rethrowAsIOException (WindowsException.java:96)
| at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:288)
| at WindowsPath.toRealPath (WindowsPath.java:944)
| at WindowsPath.toRealPath (WindowsPath.java:42)
| at (#3:1)
Therefore toRealPath() fails whether or not links are followed.
If one has these files
./dir/subdir
./aaa@ -> dir/subdir
./out.txt
then trying to get the real path of "aaa/../../out.txt" in jshell gives:
jshell> Path p = Path.of("aaa/../../out.txt")
p ==> aaa\..\..\out.txt
jshell> p.toRealPath()
| Exception java.nio.file.NoSuchFileException: C:\Users\out.txt
| at WindowsException.translateToIOException (WindowsException.java:85)
| at WindowsException.rethrowAsIOException (WindowsException.java:96)
| at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:288)
| at WindowsPath.toRealPath (WindowsPath.java:944)
| at WindowsPath.toRealPath (WindowsPath.java:42)
| at (#2:1)
jshell> p.toRealPath(LinkOption.NOFOLLOW_LINKS)
| Exception java.nio.file.NoSuchFileException: C:\Users\out.txt
| at WindowsException.translateToIOException (WindowsException.java:85)
| at WindowsException.rethrowAsIOException (WindowsException.java:96)
| at WindowsLinkSupport.getRealPath (WindowsLinkSupport.java:288)
| at WindowsPath.toRealPath (WindowsPath.java:944)
| at WindowsPath.toRealPath (WindowsPath.java:42)
| at (#3:1)
Therefore toRealPath() fails whether or not links are followed.
- duplicates
-
JDK-8315273 (fs) Path.toRealPath(LinkOption.NOFOLLOW_LINKS) fails when "../../" follows a link (win)
- Closed
- relates to
-
JDK-8306882 (fs) Path.toRealPath(LinkOption.NOFOLLOW_LINKS) fails when "../../" follows a link
- Closed