title: NPE thrown by MqttAndroidClient.publish() without any variable set to null
body: <p>This event makes me think I forgot everything about programming in Java, as a NPE is thrown without any variable set to null.</p>
  
  <p>In the next code how is it possible that the process reach the catch clause with e equal to NPE if neither msg nor mqttAndroidClient are null?</p>
  
  <p>BTW, MqttAndroidClient is not supposed to throw a NPE according to MQTT documentation.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      MqttAndroidClient mqttAndroidClient;
  
      final String serverUri = "tcp://iot.eclipse.org:1883";
  
      String clientId = "ExampleAndroidClient";
      final String publishTopic = "location";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mqttAndroidClient = MqttClientSingleton.getMqttClient(getApplicationContext(), serverUri, clientId);
          mqttAndroidClient.setCallback(new MqttCallback() {
  
              @Override
              public void connectionLost(Throwable cause) {
  
                  try {
                      mqttAndroidClient.connect();
                  } catch (Exception e) {
                      throw new RuntimeException(e);
                  }
              }
  
              @Override
              public void messageArrived(String topic, MqttMessage message) throws Exception {
  
              }
  
              @Override
              public void deliveryComplete(IMqttDeliveryToken token) {
  
              }
          });
  
          mqttAndroidClient.connect();
  
          try {
              MqttMessage msg = new MqttMessage("test".getBytes());
              mqttAndroidClient.publish(publishTopic, msg);
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
          ;
      }
  
  }
  </code></pre>
  
  <p>This is the MqttClientSingleton</p>
  
  <pre><code>import android.content.Context;
  
  import org.eclipse.paho.android.service.MqttAndroidClient;
  
  /**
   * Created by storassa on 4/30/17.
   */
  
  public class MqttClientSingleton {
      private static MqttAndroidClient client;
  
      public static MqttAndroidClient getMqttClient(Context c, String uri, String id) {
          if (client == null) {
              client = new MqttAndroidClient(c, uri, id);
              return client;
          }
          else
              return client;
      }
  }
  </code></pre>
  
  <p>This is the logcat</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.storassa.android.giulia/com.storassa.android.giulia.MainActivity}: java.lang.RuntimeException: java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
    at android.app.ActivityThread.access$800(ActivityThread.java:139)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
    at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at com.storassa.android.giulia.MainActivity.onCreate(MainActivity.java:54)
    at android.app.Activity.performCreate(Activity.java:5275)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252) 
    at android.app.ActivityThread.access$800(ActivityThread.java:139) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5103) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) 
    at dalvik.system.NativeStart.main(Native Method) 
  Caused by: java.lang.NullPointerException
    at org.eclipse.paho.android.service.MqttAndroidClient.publish(MqttAndroidClient.java:812)
    at org.eclipse.paho.android.service.MqttAndroidClient.publish(MqttAndroidClient.java:668)
    at com.storassa.android.giulia.MainActivity.onCreate(MainActivity.java:52)
    at android.app.Activity.performCreate(Activity.java:5275) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252) 
    at android.app.ActivityThread.access$800(ActivityThread.java:139) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5103) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) 
    at dalvik.system.NativeStart.main(Native Method) 
  </code></pre>
  
  <hr>
  
  <p>NEW EDIT</p>
  
  <p>I added the MqttClientSingleton code and the line with mqttAndroidClient.connect() that got lost in the copy and paste</p>