title: Java: java.lang.NullPointerException at booleanValue()
body: <p>I have function foo() that returns true/false/null.</p>
  
  <p>I have this piece of code:</p>
  
  <pre><code>Boolean flag = foo();
  if (flag != null){
  .....
  }
  </code></pre>
  
  <p>When inspecting the <code>if</code> statement, I get the following exception: <code>java.lang.NullPointerException at booleanValue()</code></p>
  
  <p>Seems that it tries to evaluate its primitive value and compare it . However, this is what I do NOT want it to do. I want to check whether it is initialized...</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>