title: Spark RDD isEmpty method throws NullPointerException, when RDD is not null
body: <p>This took me by surprise (while explaining to someone, unfortunately).</p>
  
  <p>I am curious about what happens internally in spark in the following snippet.</p>
  
  <pre><code>val rdd = sc.parallelize(null)
  rdd == null //false
  rdd.isEmpty //NullPointerException
  </code></pre>
  
  <p>Before you ask, I agree parallelizing null is arguable, but this is simply a condition we run into in our streaming application.</p>
  
  <p>I read somewhere that 'isEmpty' goes in and internally calls <code>rdd.take(1)</code>, which ultimately throws the exception, but this seems inconsistent with language behavior. Also, I found that in some cases it takes longer (few seconds sometimes) to return with an NPE, although that could be because it goes over the network looking for data.</p>
  
  <p>So the question is, why does this happen? Is this expected behavior? Is there a better way to deal with this than caching NPE?</p>
  
  <p>Many thanks in advance!</p>