Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Null pointer exception caused by accessing a null token returned from TokenStore in java mqtt client library

I'm using the 0.4.0 version of the java mqtt client library in an android application.

Here's what happens (QoS=2 messages only):

1. CommsReceiver thread reads  ack message (PUBCOMP)  from network

2.  Then it retrieves the token for the specified message from the token store and calls ClientState.notifyReceivedAck() passing the message received from network.

3. Then ClientState.notifyReceivedAck()  tries to retrieve the token from the token store  but the token is null causing a NPE when ClientState.notifyResult() method tries to call Token.internalTok.markComplete() on the NULL token.


Looking at the logs of the mqtt server broker  i see that a PUBREC message was published to the client twice after which the broker send two PUBCOMP messages with same message id (after the client has sent PUBREL as specified in the mqtt specification).

I think this may be a threading issue in the mqtt java client library resulting of another thread removing the message from the token store after the  CommsReceiver  has read the message from the TokenStore ? Or is that happening because the broker sends two messages with the same id ?

I'ts really hard to reproduce this NPE (it happens something like once in 20 reconnects). I'm causing it by repeatedly publishing messages to  a topic and then turning off internet connectivity on the device and then turning it back on again.  

I've also tried the 0.9.0 version of the client library but the problem remains.

Do you have any idea what maybe causing this and do you think my conclusions are right ?  

Back to the top