title: Java NullPointerException when calling listFiles() on a directory
body: <p>I have a series of folders containing books on a server which I am accessing with this piece of code. I want to make each of these folders an object so I can do some work with the files inside them later on. I'm trying to use this method to return a list of the folders as Book objects.</p>
  
  <pre><code>public List&lt;Book&gt; getBooks(File folder){
      List&lt;Book&gt; books = new ArrayList&lt;Book&gt;();
      for (File f : folder.listFiles()){
          if (f.isDirectory()){
              System.out.println(f.getAbsolutePath() + "" + f.listFiles());
              books.add(new Book(f));
          }
      }
      return books;
  }
  </code></pre>
  
  <p>The println statement in this block is printing, as it should, the direct path to the folder and then the memory address along with some other information. However, somewhere in the folder it is printing out null when listFiles() is called. The folder that it is doing this on is not empty. This supposedly empty folder is then passed to my class init method.</p>
  
  <pre><code>public Book(File bookFolder) {
      this.bookFolder = bookFolder;
      this.bookPath = bookFolder.getAbsolutePath();
  
      System.out.println(bookFolder + " " + bookFolder.listFiles());
  
      for (File f : bookFolder.listFiles()) {
          ...
      }
  }
  </code></pre>
  
  <p>The println statement in this block prints out the exact same path to the folder and then a different memory address, which is also expected. When it hits the "empty" folder it prints null for the memory address again.</p>
  
  <p>Now, for the real issue, the line with the for loop is where the program crashes and throws a NullPointerException which isn't even described in the documentation for the listFiles method.</p>
  
  <p>Why could this be happening? Also, why are my non-empty folders returning null?</p>