Java stream filter null pointer issue
<p>I have the following stream:</p>

<pre><code>services = services.stream()
        .filter(service -&gt; (service.getType().isEmpty() || service.getType().equals(type)))
        .collect(Collectors.toList());
</code></pre>

<p>where <code>service.type</code> is string, and <code>type</code> is also a string. My filter should return all services with its <code>type</code> equal to null (or simply blank), or the given type.</p>

<p>This throws me an error of:</p>

<blockquote>
  <p>java.lang.NullPointerException: null  at
  com.eternity.service.OrderService.lambda$getServicesForOrder$0(OrderService.java:140)
  ~[classes/:na]    at
  java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
  ~[na:1.8.0_77]    at
  java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
  ~[na:1.8.0_77]    at
  java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
  ~[na:1.8.0_77]    at
  java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
  ~[na:1.8.0_77]    at
  java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
  ~[na:1.8.0_77]    at
  java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  ~[na:1.8.0_77]    at
  java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
  ~[na:1.8.0_77]    at
  com.eternity.service.OrderService.getServicesForOrder(OrderService.java:141)
  ~[classes/:na]</p>
</blockquote>

<p>What am I missing?</p>