title: Java 7 walkFileTree calling visitFile on directories
body: <p>Say I have the following directory structure</p>
  
  <pre><code>/root/dir
  /root/dir/file1.txt
  /root/dir/subdir
  /root/dir/subdir/file2.txt
  </code></pre>
  
  <p>And let's say I'll be using the following visitor:</p>
  
  <pre><code>class MyFileVisitor extends SimpleFileVisitor&lt;Path&gt; {
  
    @Override
    public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
    throws IOException {
      if(Files.isDirectory(file)) {
        throw new IllegalStateException("WAT!? Visiting directory: "+file.toAbsolutePath().toString());
      }
      System.out.println("Visiting file: "+file.toAbsolutePath().toString());
      return super.visitFile(file, attrs);
    }
  </code></pre>
  
  <p>If we use the simple overload of walkFileTree:</p>
  
  <pre><code>Files.walkFileTree(Paths.get("/root/dir"), new MyFileVisitor());  
  </code></pre>
  
  <p>Everything goes according to plan and we see the following output:</p>
  
  <pre><code>Visiting file: /root/dir/file1.txt
  Visiting file: /root/dir/subdir/file2.txt
  </code></pre>
  
  <p>But when we try setting the max depth, things start to break down:</p>
  
  <pre><code>Files.walkFileTree(Paths.get("/root/dir"), EnumSet.noneOf(FileVisitOption.class), 1, new MyFileVisitor());
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Visiting file: /root/dir/file1.txt
  
  java.lang.IllegalStateException: WAT!? Visting directory: /root/dir/subdir
  </code></pre>
  
  <p>I'm pretty sure this is a bug, but I wanted to ask the community first: Is there something I'm missing and this is actually expected behavior? Thanks for confirming!</p>
  
  <p>Details:</p>
  
  <pre><code>java -version
  java version "1.7.0_45"
  Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
  Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
  </code></pre>