ARTEMIS-3770 mitigate potential NPE

This was being triggered by
org.apache.activemq.artemis.tests.integration.routing.MQTTRedirectTest.
This commit is contained in:
Justin Bertram 2022-05-10 12:12:35 -05:00 committed by clebertsuconic
parent bed9af2e51
commit 3a0658c202
1 changed files with 7 additions and 3 deletions

View File

@ -448,10 +448,14 @@ public class MQTTProtocolHandler extends ChannelInboundHandlerAdapter {
private void disconnectExistingSession(MQTTConnection existingConnection) {
if (existingConnection != null) {
MQTTSession existingSession = session.getProtocolManager().getSessionState(session.getConnection().getClientID()).getSession();
if (session.getVersion() == MQTTVersion.MQTT_5) {
existingSession.getProtocolHandler().sendDisconnect(MQTTReasonCodes.SESSION_TAKEN_OVER);
if (existingSession != null) {
if (session.getVersion() == MQTTVersion.MQTT_5) {
existingSession.getProtocolHandler().sendDisconnect(MQTTReasonCodes.SESSION_TAKEN_OVER);
}
existingSession.getConnectionManager().disconnect(false);
} else {
existingConnection.disconnect(false);
}
existingSession.getConnectionManager().disconnect(false);
}
}