3333import java .io .UncheckedIOException ;
3434import java .nio .file .Files ;
3535import java .nio .file .Path ;
36+ import java .util .HashSet ;
37+ import java .util .Set ;
3638
3739import jdk .test .lib .Platform ;
3840
@@ -51,6 +53,7 @@ public class ToRealPath {
5153 static final Path SUBDIR ;
5254 static final Path FILE ;
5355 static final Path LINK ;
56+ static final Set <Path > extraDeletions ;
5457
5558 static {
5659 try {
@@ -59,6 +62,7 @@ public class ToRealPath {
5962 FILE = Files .createFile (DIR .resolve ("foo" ));
6063 LINK = DIR .resolve ("link" );
6164 SUPPORTS_LINKS = TestUtil .supportsSymbolicLinks (DIR );
65+ extraDeletions = new HashSet <Path >();
6266 } catch (IOException e ) {
6367 throw new UncheckedIOException (e );
6468 }
@@ -154,8 +158,15 @@ public void noCollapseDots1() throws IOException {
154158 System .out .println ("p: " + p );
155159 Path path = LINK .resolve (p );
156160 System .out .println ("path: " + path );
161+ if (Platform .isWindows () && Files .notExists (path )) {
162+ Files .createFile (path );
163+ extraDeletions .add (path );
164+ }
157165 System .out .println ("no follow: " + path .toRealPath (NOFOLLOW_LINKS ));
158- assertEquals (path .toRealPath (NOFOLLOW_LINKS ), path );
166+ if (Platform .isWindows ())
167+ assertTrue (Files .isSameFile (path .toRealPath (NOFOLLOW_LINKS ), path ));
168+ else
169+ assertEquals (path .toRealPath (NOFOLLOW_LINKS ), path );
159170
160171 Files .delete (sub );
161172 Files .delete (sub .getParent ());
@@ -177,8 +188,15 @@ public void noCollapseDots2() throws IOException {
177188 Path p = Path .of ("aaa" , ".." , ".." , "bbb" , ".." , ".." , "out.txt" );
178189 Path path = DIR .resolve (p );
179190 System .out .println ("path: " + path );
191+ if (Platform .isWindows () && Files .notExists (path )) {
192+ Files .createFile (path );
193+ extraDeletions .add (path );
194+ }
180195 System .out .println ("no follow: " + path .toRealPath (NOFOLLOW_LINKS ));
181- assertEquals (path .toRealPath (NOFOLLOW_LINKS ), path );
196+ if (Platform .isWindows ())
197+ assertTrue (Files .isSameFile (path .toRealPath (NOFOLLOW_LINKS ), path ));
198+ else
199+ assertEquals (path .toRealPath (NOFOLLOW_LINKS ), path );
182200 System .out .println (path .toRealPath ());
183201
184202 Files .delete (sub );
@@ -235,5 +253,7 @@ public static void cleanup() throws IOException {
235253 Files .delete (FILE );
236254 Files .delete (SUBDIR );
237255 Files .delete (DIR );
256+ for (Path p : extraDeletions )
257+ Files .deleteIfExists (p );
238258 }
239259}
0 commit comments