title: Kafka - NullPointerException in Send
body: <p>I'm using Kafka from a Spark application to send some notifications to a topic. I see loads of the following exception in my Spark logs, and the message is not delivered to the topic. </p>
  
  <p>15/09/08 03:29:24 ERROR Sender: Uncaught error in kafka producer I/O thread: </p>
  
  <pre><code>java.lang.NullPointerException
      at org.apache.kafka.common.network.NetworkReceive.complete(NetworkReceive.java:48)
      at org.apache.kafka.common.network.Selector.poll(Selector.java:249)
      at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:192)
      at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:191)
      at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:122)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I'm not sure what causes this error and looking at the source, it seems that either size or buffer variable in NetworkReceive.java is null. </p>
  
  <p>Scanning through the logs, I see that prior to this log entry, there's one occurrence of the following message.</p>
  
  <pre><code>15/09/08 03:29:24 ERROR Sender: Uncaught error in kafka producer I/O thread: 
  java.lang.IllegalStateException: Invalid request (size = -2097152000)
      at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:68)
      at org.apache.kafka.common.network.Selector.poll(Selector.java:248)
      at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:192)
      at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:191)
      at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:122)
      at java.lang.Thread.run(Thread.java:745)
  15
  </code></pre>