title: NullPointerException in native java code while performing parallelStream.forEach(..)
body: <p>I have the following exception (the stacktrace):</p>
  
  <pre><code>java.lang.NullPointerException
  at sun.reflect.GeneratedConstructorAccessor171.newInstance(Unknown Source) ~[?:?]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_40]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[?:1.8.0_40]
  at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598) ~[?:1.8.0_40]
  at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677) ~[?:1.8.0_40]
  at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735) ~[?:1.8.0_40]
  at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160) ~[?:1.8.0_40]
  at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174) ~[?:1.8.0_40]
  at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) ~[?:1.8.0_40]
  at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[?:1.8.0_40]
  at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583) ~[?:1.8.0_40]
  at com.tradair.tnet.services.trades.TradeService.updateUnrealizedPNL(TradeService.java:173) ~[tnet.jar:5.1.1.0-SNAPSHOT]
  </code></pre>
  
  <p>which starts at my <code>TradeService</code> class here:</p>
  
  <pre><code>    public void updateUnrealizedPNL(Set&lt;Org&gt; orgsToCaluclate, Set&lt;Org&gt; orgsToSendUpdate) {
      orgsToCaluclate.parallelStream().forEach(o -&gt; {
          pnlService.updateMidPrices(o);
          Collection&lt;SystemTradeOrder&gt; allLiveTradesByOrgId = tradesRepository.getAllLiveTradesByOrgId(o.getId());
          updateUnrealizedPNL(o, allLiveTradesByOrgId);
      });
  
      // more code ....
  </code></pre>
  
  <p>So it looks like the exception is thrown inside java native code while running <code>forEach(..)</code> method.
  I mean, the <code>NullPointerException</code> isn't thrown from my own code - not from my consumer function which appears as the argument in <code>forEach(..)</code> method.</p>
  
  <p>I double checked that there is no modification to the <code>orgsToCaluclate</code> set when this piece of code runs.</p>
  
  <p>This is the initialization of  <code>orgsToCaluclate</code>:</p>
  
  <pre><code>        Set&lt;Org&gt; orgsToCaluclate = getMarginOrgs();
          orgsToCaluclate = orgsToCaluclate.stream()
                  .filter(org -&gt; !isOrgInCloseout(org.getId())).collect(Collectors.toSet());
  </code></pre>
  
  <p>Any thoughts?..</p>