Under some circunstances, a SUBSCRIBE or UNSUBSCRIBE message might be persisted in the persistBufferedMessage is set when the client has lost the connection with the server.
In this scenario, the message enters in the second branch of the conditional: else if (disconnectedMessageBuffer != null) { ...
And the code tries to persist it in the buffer, what ends up causing a ClassCastException when trying to store the message in the buffer as a MQTTPublish object in the ClientState class:
this.persistence.put(key, (MqttPublish)message);
My suggestion, which may be insufficient in case of a race condition, is to implement the same safe-check that was added in the issue 606 validating the message is an instance of the MqttPublish class:
Please fill out the form below before submitting, thank you!
This bug relates to:
And this fix:
Under some circunstances, a SUBSCRIBE or UNSUBSCRIBE message might be persisted in the persistBufferedMessage is set when the client has lost the connection with the server.
In this scenario, the message enters in the second branch of the conditional:
else if (disconnectedMessageBuffer != null) { ...
And the code tries to persist it in the buffer, what ends up causing a ClassCastException when trying to store the message in the buffer as a MQTTPublish object in the ClientState class:My suggestion, which may be insufficient in case of a race condition, is to implement the same safe-check that was added in the issue 606 validating the message is an instance of the MqttPublish class: