jdk/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java
changeset 10891 8c554ab7cfed
parent 7668 d4a77089c587
child 14342 8435a30053c1
--- a/jdk/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java	Fri Oct 28 07:18:54 2011 -0700
+++ b/jdk/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java	Sun Oct 30 14:53:43 2011 +0000
@@ -124,26 +124,27 @@
         private boolean atEof;
         private String first;
         private Path nextEntry;
+        private String prefix;
 
         WindowsDirectoryIterator(String first) {
             atEof = false;
             this.first = first;
+            if (dir.needsSlashWhenResolving()) {
+                prefix = dir.toString() + "\\";
+            } else {
+                prefix = dir.toString();
+            }
+        }
+
+        // links to self and parent directories are ignored
+        private boolean isSelfOrParent(String name) {
+            return name.equals(".") || name.equals("..");
         }
 
         // applies filter and also ignores "." and ".."
         private Path acceptEntry(String s, BasicFileAttributes attrs) {
-            if (s.equals(".") || s.equals(".."))
-                return null;
-            if (dir.needsSlashWhenResolving()) {
-                StringBuilder sb = new StringBuilder(dir.toString());
-                sb.append('\\');
-                sb.append(s);
-                s = sb.toString();
-            } else {
-                s = dir + s;
-            }
             Path entry = WindowsPath
-                .createFromNormalizedPath(dir.getFileSystem(), s, attrs);
+                .createFromNormalizedPath(dir.getFileSystem(), prefix + s, attrs);
             try {
                 if (filter.accept(entry))
                     return entry;
@@ -157,7 +158,7 @@
         private Path readNextEntry() {
             // handle first element returned by search
             if (first != null) {
-                nextEntry = acceptEntry(first, null);
+                nextEntry = isSelfOrParent(first) ? null : acceptEntry(first, null);
                 first = null;
                 if (nextEntry != null)
                     return nextEntry;
@@ -184,6 +185,10 @@
                         return null;
                     }
 
+                    // ignore link to self and parent directories
+                    if (isSelfOrParent(name))
+                        continue;
+
                     // grab the attributes from the WIN32_FIND_DATA structure
                     // (needs to be done while holding closeLock because close
                     // will release the buffer)