title: Getting null pointer exception when running saveAsNewAPIHadoopDataset in scala spark2 to hbase
body: <p>I am saving a puts RDD to Hbase using saveAsNewAPIHadoopDataset. Below is my job creation and submition.    </p>
  
  <pre><code>    val outputTableName = "test3"
      val conf2 = HBaseConfiguration.create()
      conf2.set("hbase.zookeeper.quorum", "xx.xx.xx.xx")
      conf2.set("hbase.mapred.outputtable", outputTableName)
      conf2.set("mapreduce.outputformat.class", "org.apache.hadoop.hbase.mapreduce.TableOutputFormat")
  
      val job = createJob(outputTableName, conf2)
      val outputTable = sc.broadcast(outputTableName)
      val hbasePuts = simpleRdd.map(k =&gt; convertToPut(k, outputTable))
  
      hbasePuts.saveAsNewAPIHadoopDataset(job.getConfiguration)
  </code></pre>
  
  <p>This is my job creation function </p>
  
  <pre><code>def createJob(table: String, conf: Configuration): Job = {
      conf.set(TableOutputFormat.OUTPUT_TABLE, table)
      val job = Job.getInstance(conf, this.getClass.getName.split('$')(0))
      job.setOutputFormatClass(classOf[TableOutputFormat[String]])
      job
    }
  </code></pre>
  
  <p>This function converts data in Hbase format</p>
  
  <pre><code>def convertToPut(k: (String, String, String), outputTable: Broadcast[String]): (ImmutableBytesWritable, Put) = {
      val rowkey = k._1
      val put = new Put(Bytes.toBytes(rowkey))
      val one = Bytes.toBytes("cf1")
      val two = Bytes.toBytes("cf2")
  
      put.addColumn(one, Bytes.toBytes("a"), Bytes.toBytes(k._2))
      put.addColumn(two, Bytes.toBytes("a"), Bytes.toBytes(k._3))
      (new ImmutableBytesWritable(Bytes.toBytes(outputTable.value)), put)
    }
  </code></pre>
  
  <p>This is the error i am getting at line 125 which is :hbasePuts.saveAsNewAPIHadoopDataset(job.getConfiguration)</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at org.apache.hadoop.hbase.security.UserProvider.instantiate(UserProvider.java:122)
      at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:214)
      at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
      at org.apache.hadoop.hbase.mapreduce.TableOutputFormat.checkOutputSpecs(TableOutputFormat.java:177)
      at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsNewAPIHadoopDataset$1.apply$mcV$sp(PairRDDFunctions.scala:1099)
      at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsNewAPIHadoopDataset$1.apply(PairRDDFunctions.scala:1085)
      at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsNewAPIHadoopDataset$1.apply(PairRDDFunctions.scala:1085)
      at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
      at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
      at org.apache.spark.rdd.RDD.withScope(RDD.scala:362)
      at org.apache.spark.rdd.PairRDDFunctions.saveAsNewAPIHadoopDataset(PairRDDFunctions.scala:1085)
      at ScalaSpark$.main(ScalaSpark.scala:125)
      at ScalaSpark.main(ScalaSpark.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:498)
      at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:738)
      at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:187)
      at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:212)
      at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:126)
      at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
  </code></pre>