title: Why am I getting a NullPointerException when fetching values from Futures?
body: <p>I'm using and <code>ExecutorService</code> to concurrently run some <code>Callables</code>. Here's a simplified version of my code:</p>
  
  <pre><code>ArrayList&lt;Book&gt; objResults = new ArrayList&lt;Book&gt;();
  ExecutorService esrExecutor = Executors.newFixedThreadPool(2);
  Set&lt;Callable&lt;ArrayList&lt;Book&gt;&gt;&gt; setCallables = new HashSet&lt;Callable&lt;ArrayList&lt;Book&gt;&gt;&gt;();
  
  setCallables.add(new Callable&lt;ArrayList&lt;Book&gt;&gt;() {
  
      public ArrayList&lt;Book&gt; call() throws Exception {    
          ArrayList&lt;Book&gt; objAmazonResults = new ArrayList&lt;Book&gt;();
  
          try {    
              Amazon objAmazon = new Amazon();
              objAmazonResults = objAmazon.doSearch(strQuery);    
          } catch (Exception e) {
              e.printStackTrace();
          }    
          return objAmazonResults;    
      }
  
  });
  
  
  List&lt;Future&lt;ArrayList&lt;Book&gt;&gt;&gt; lstFutures;
  try {
      lstFutures = esrExecutor.invokeAll(setCallables);
  
      for(Future&lt;ArrayList&lt;Book&gt;&gt; futFuture : lstFutures){
          if (futFuture.get().isEmpty() == false) //NullPointerException occurs here
              objResults.addAll(futFuture.get());
      }
  } catch (InterruptedException e) {
      e.printStackTrace();
  } catch (ExecutionException e) {
      e.printStackTrace();
  }
  
  esrExecutor.shutdown();
  </code></pre>
  
  <p>I get a <code>NullPointerException</code> on this bit of code <code>if (futFuture.get().isEmpty() == false)</code>. I can't seem to figure out why or how this bit of code can possibly be null.</p>
  
  <p>If you look at my <code>Callable</code> you'll see that I'm trapping all exceptions and simply printing the stacktrace and I always return <code>new ArrayList&lt;Book&gt;()</code>.</p>
  
  <p>I'm not much for helping other debug my code soup on SO but sometimes everyone hits a roadblock but this kind of exceptions has taught me one thing — when chaining methods together, it's always harder to debug.</p>