title: Java: BufferedWriter NullPointerException
body: <p>I am attempting to write a method that has to take in a <code>Writer</code> object and use that to provide output to a file. The current code I have is throwing a <code>NullPointerException</code>, presumably because either there is an error in how I am creating my BufferedWriter or else in some instances <code>w</code> (the <code>Writer</code> object) is being passed as <code>null</code>. I have no control over what is passed as <code>w</code>, and cannot change the exceptions that this method is able to throw.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>public void write(Writer w, Stat s) throws IOException {
      try{
          BufferedWriter writeFile = new BufferedWriter(w);
          writeFile.write(s.getData());
          writeFile.flush();
      } catch (IOException e){
          ...
      }
  }
  </code></pre>
  
  <p>Is there something I'm doing wrong?</p>
  
  <p>(This assignment arises out of homework, but this question isn't the homework itself)</p>