eclipse / paho.mqtt.android

MQTT Android
Other
2.92k stars 883 forks source link

NullPointerException in MqttCallbackExtended #400

Open Turbozanik opened 4 years ago

Turbozanik commented 4 years ago

Gist: https://gist.github.com/Turbozanik/bacc394cca10430e189bbf5e379abaf0

Problem description: NullPointerException in line 144 after creating new AndroidMqttClient. Hotfix: We have added 0.5 second delay before and after calling init method.

We have an IoT application, that is receiving mqtt server ip and mac over mdns. So we have to recreate AndroidMqttClient every time we are receiving new data(for example user has changed his router and the mqtt server ip has been updated). You can see this code in line 183. To create new AndroidMqttClient and reset all it callbacks we are executing init() method.(line 183) And any action we do after that will result in NPE in line 144.

Maybe you can explain why does this library behave like this? And maybe some approaches how can I fix this without 0.5 second workaround?

Atomics were added for testing purposes.