--- old/src/java.base/share/classes/java/nio/file/FileTreeIterator.java 2016-09-14 20:47:54.000000000 +0000 +++ new/src/java.base/share/classes/java/nio/file/FileTreeIterator.java 2016-09-14 20:47:54.000000000 +0000 @@ -28,10 +28,9 @@ 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; /** @@ -62,13 +61,14 @@ * @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;