title: How do I identify the null pointer exception in completable future?
body: <p>I have a completable future code which throws NPE. I am unable to reproduce the exception in my local.</p>
  
  <p>I have tried acceptance test and unit test for the code but it's not giving the exact error response.</p>
  
  <pre><code>    final List&lt;CompletableFuture&lt;Map&lt;K, V&gt;&gt;&gt; completableFutures = 
      copy.stream()                                                                         
      .map(copy -&gt; getRespForId(requestContext, copy))                                                                          
      .collect(Collectors.toList());
  
      return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture&lt;?&gt;[0]))
                 .thenApply(future -&gt; completableFutures.stream()
                                          .map(CompletableFuture::join)
                                          .flatMap(longMap -&gt; longMap.entrySet().stream())
                                          .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
  </code></pre>
  
  <p>Expected is</p>
  
  <pre><code>Caused by: java.util.concurrent.CompletionException: java.lang.NullPointerException
      at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
      at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
      at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
      at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)
      at java.base/java.util.concurrent.CompletableFuture.postFire(Unknown Source)
      at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
      at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
      at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
      at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
      at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
      at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
      at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
  Caused by: java.lang.NullPointerException: null
      at java.base/java.util.Objects.requireNonNull(Unknown Source)
      at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Unknown Source)
  </code></pre>