Spark RDD throwing NullPointerException
<p>I am facing issue when I try to get some products from hive table and process/apply rools in spark. </p>

<pre><code>//function which return products from Hive table
def getProductsList(hiveContext: org.apache.spark.sql.hive.HiveContext): scala.collection.mutable.MutableList[Product] = {
        val products = scala.collection.mutable.MutableList[Product]()      
                val results = hiveContext.sql("select item_id,value from  details where  type_id=12");
        val collection = results.collect();
        var i = 0;
        results.collect.foreach(t =&gt; {
          val product = new Product(collection(i)(0).asInstanceOf[Long], collection(i)(1).asInstanceOf[String]); 
          i = i+ 1;
          products += product
        })    
        products 
      }
</code></pre>

<p>Calling getProductsList function and applying drools rools on products.</p>

<pre><code>    val randomProducts = this.getProductsList(hiveContext)
        val rdd = ssc.sparkContext.parallelize(randomProducts)         
        val evaluatedProducts = rdd.mapPartitions(incomingProducts =&gt; {     
  print("Hello"); 
    rulesExecutor.evalRules(incomingProducts) })
        val productdf = hiveContext.applySchema(evaluatedProducts, classOf[Product])
    })
</code></pre>

<p>As showin in above  rdd mapPartitions iteration not happening and it is throwing following error. But I am sure rdd is not empty.</p>

<pre><code>Exception in thread "main" java.lang.NullPointerException
        at org.spark-project.guava.reflect.TypeToken.method(TypeToken.java:465)
        at org.apache.spark.sql.catalyst.JavaTypeInference$$anonfun$2.apply(JavaTypeInference.scala:103)
        at org.apache.spark.sql.catalyst.JavaTypeInference$$anonfun$2.apply(JavaTypeInference.scala:102)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:108)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
        at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:108)
        at org.apache.spark.sql.catalyst.JavaTypeInference$.org$apache$spark$sql$catalyst$JavaTypeInference$$inferDataType(JavaTypeInference.scala:102)
        at org.apache.spark.sql.catalyst.JavaTypeInference$.inferDataType(JavaTypeInference.scala:47)
        at org.apache.spark.sql.SQLContext.getSchema(SQLContext.scala:995)
        at org.apache.spark.sql.SQLContext.createDataFrame(SQLContext.scala:488)
        at org.apache.spark.sql.SQLContext.applySchema(SQLContext.scala:1028)
        at com.cloudera.sprue.ValidateEan$.main(ValidateEan.scala:70)
        at com.cloudera.sprue.ValidateEan.main(ValidateEan.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:672)
        at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
        at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
16/05/05 07:44:48 INFO SparkContext: Invoking stop() from shutdown hook
</code></pre>

<p>Please help me out to resolve this issue.</p>