From 49de06e500e79379f4fab45bf26a6904cf420061 Mon Sep 17 00:00:00 2001 From: andrea Date: Fri, 30 Aug 2013 10:46:15 +0200 Subject: [PATCH] Moved assertions to RuntimeError to let error emerge in runtime when assertions are disabled --- .../messaging/spi/impl/SimpleMessaging.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/broker/src/main/java/org/dna/mqtt/moquette/messaging/spi/impl/SimpleMessaging.java b/broker/src/main/java/org/dna/mqtt/moquette/messaging/spi/impl/SimpleMessaging.java index a629243d..8c57f078 100644 --- a/broker/src/main/java/org/dna/mqtt/moquette/messaging/spi/impl/SimpleMessaging.java +++ b/broker/src/main/java/org/dna/mqtt/moquette/messaging/spi/impl/SimpleMessaging.java @@ -333,7 +333,9 @@ public class SimpleMessaging implements IMessaging, EventHandler { publish2Subscribers(topic, qos, message, retain, evt.getMessageID()); if (qos == QOSType.LEAST_ONE) { - assert publishKey != null; + if (publishKey == null) { + throw new RuntimeException("Found a publish key null for QoS " + qos + " for message " + evt); + } m_storageService.cleanInFlight(publishKey); sendPubAck(new PubAckEvent(evt.getMessageID(), evt.getClientID())); } @@ -496,9 +498,13 @@ public class SimpleMessaging implements IMessaging, EventHandler { } try { - assert m_clientIDs != null; + if (m_clientIDs == null) { + throw new RuntimeException("Internal bad error, found m_clientIDs to null while it should be initialized, somewhere it's overwritten!!"); + } LOG.debug("clientIDs are " + m_clientIDs); - assert m_clientIDs.get(clientId) != null; + if (m_clientIDs.get(clientId) == null) { + throw new RuntimeException(String.format("Can't find a ConnectionDEwcriptor for client %s in cache %s", clientId, m_clientIDs)); + } LOG.debug("Session for clientId " + clientId + " is " + m_clientIDs.get(clientId).getSession()); m_clientIDs.get(clientId).getSession().write(pubMessage); }catch(Throwable t) { @@ -515,9 +521,13 @@ public class SimpleMessaging implements IMessaging, EventHandler { pubAckMessage.setMessageID(evt.getMessageId()); try { - assert m_clientIDs != null; + if (m_clientIDs == null) { + throw new RuntimeException("Internal bad error, found m_clientIDs to null while it should be initialized, somewhere it's overwritten!!"); + } LOG.debug("clientIDs are " + m_clientIDs); - assert m_clientIDs.get(clientId) != null; + if (m_clientIDs.get(clientId) == null) { + throw new RuntimeException(String.format("Can't find a ConnectionDEwcriptor for client %s in cache %s", clientId, m_clientIDs)); + } LOG.debug("Session for clientId " + clientId + " is " + m_clientIDs.get(clientId).getSession()); m_clientIDs.get(clientId).getSession().write(pubAckMessage); }catch(Throwable t) {