< prev index next >

src/java.base/share/classes/java/nio/file/FileTreeIterator.java

Print this page

        

@@ -26,14 +26,13 @@
 package java.nio.file;
 
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.UncheckedIOException;
-import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 import java.util.NoSuchElementException;
-import java.util.Objects;
 import java.nio.file.FileTreeWalker.Event;
 
 /**
  * An {@code Iterator to iterate over the nodes of a file tree.
  *

@@ -60,17 +59,19 @@
      * @throws  IOException
      *          if an I/O errors occurs opening the starting file
      * @throws  SecurityException
      *          if the security manager denies access to the starting file
      * @throws  NullPointerException
-     *          if {@code start} or {@code options} is {@ocde null} or
+     *          if {@code start} or {@code options} is {@code null} or
      *          the options array contains a {@code null} element
      */
     FileTreeIterator(Path start, int maxDepth, FileVisitOption... options)
         throws IOException
     {
-        this.walker = new FileTreeWalker(Arrays.asList(options), maxDepth);
+        // Since options may be a mutable array, use List.of to copy the array 
+        // and prevent TOCTOU.
+        this.walker = new FileTreeWalker(List.of(options), maxDepth);
         this.next = walker.walk(start);
         assert next.type() == FileTreeWalker.EventType.ENTRY ||
                next.type() == FileTreeWalker.EventType.START_DIRECTORY;
 
         // IOException if there a problem accessing the starting file
< prev index next >