title: Why does findFirst() throw a NullPointerException if the first element it finds is null?
body: <p>Why does this throw a <code>java.lang.NullPointerException</code>?</p>
  <pre><code>List&lt;String&gt; strings = new ArrayList&lt;&gt;();
  strings.add(null);
  strings.add(&quot;test&quot;);
  
  String firstString = strings.stream()
          .findFirst()      // Exception thrown here
          .orElse(&quot;StringWhenListIsEmpty&quot;);
          //.orElse(null);  // Changing the `orElse()` to avoid ambiguity
  </code></pre>
  <p>The first item in <code>strings</code> is <code>null</code>, which is a perfectly acceptable value. Furthermore, <code>findFirst()</code> returns an <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html" rel="noreferrer">Optional</a>, which makes even more sense for <code>findFirst()</code> to be able to handle <code>null</code>s.</p>
  <p>EDIT: updated the <code>orElse()</code> to be less ambiguous.</p>