[Demonstration 1]

[Buggy Method]
public void agregarServicioMesa(Producto p, int cantidad, String descripcion, int mesa) {
    Mesa ms = ss.buscarMesa(mesa);
    if (ms.getEstado().equals(EstadosMesa.Cerrada)) {
        ItemServicio is = new ItemServicio(p, cantidad, descripcion, ms);
        ms.getServicio().add(is);
        ss.getPedidosSinAsignar().add(is);
    }
}

[Buggy Hunk]
if(ms.getEstado().equals(EstadosMesa.Cerrada)){

[Patch]
if(ms.getEstado().equals(EstadosMesa.EnUso)){

[Demonstration 2]

[Buggy Method]
private void sendPublish(String clientId, String topic, AbstractMessage.QOSType qos, ByteBuffer message, boolean retained, Integer messageID) {
    LOG.debug("sendPublish invoked clientId [{}] on topic [{}] QoS {} retained {} messageID {}", clientId, topic, qos, retained, messageID);
    PublishMessage pubMessage = new PublishMessage();
    pubMessage.setRetainFlag(retained);
    pubMessage.setTopicName(topic);
    pubMessage.setQos(qos);
    pubMessage.setPayload(message);
    //        LOG.info("send publish message to [{}] on topic [{}] content [{}]", clientId, topic, DebugUtils.payload2Str(message));
    //set the PacketIdentifier only for QoS > 0
    if (pubMessage.getQos() != AbstractMessage.QOSType.MOST_ONE) {
        pubMessage.setMessageID(messageID);
    } else {
        if (messageID != null) {
            throw new RuntimeException("Internal bad error, trying to forwardPublish a QoS 0 message with PacketIdentifier: " + messageID);
        }
    }
    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);
    if (m_clientIDs.get(clientId) == null) {
        //重新清理异常的订阅者
        subscriptions.removeSubscription(topic, clientId);
        LOG.error("Can't find a ConnectionDescriptor for client [{}] in cache", clientId);
        throw new RuntimeException(String.format("Can't find a ConnectionDescriptor for client <%s> in cache", clientId));
    }
    LOG.debug("Session for clientId {} is {}", clientId, m_clientIDs.get(clientId).getSession());
    //        m_clientIDs.get(clientId).getSession().write(pubMessage);
    publishToMainDisruptor(new OutputMessagingEvent(m_clientIDs.get(clientId).getSession(), pubMessage));
}

[Buggy Hunk]
subscriptions.removeSubscription(topic, clientId);

[Patch]
reClean(clientId);

[Demonstration 3]

[Buggy Method]
private void processPublish(String clientID, String topic, QOSType qos, ByteBuffer message, boolean retain, Integer messageID) {
    LOG.info("PUBLISH from clientID [{}] on topic [{}] with QoS {} content[{}]", clientID, topic, qos, DebugUtils.payload2Str(message));
    if (qos == AbstractMessage.QOSType.MOST_ONE) {
        //QoS0
        forward2Subscribers(topic, qos, message, retain, messageID);
    } else if (qos == AbstractMessage.QOSType.LEAST_ONE) {
        PublishEvent inFlightEvt = new PublishEvent(topic, qos, message, retain, clientID, messageID);
        //TODO use a message store for TO PUBLISH MESSAGES it has nothing to do with inFlight!!
        m_messagesStore.addInFlight(inFlightEvt, clientID, messageID);
        forward2Subscribers(topic, qos, message, retain, messageID);
        m_messagesStore.cleanInFlight(clientID, messageID);
        //NB the PUB_ACK could be sent also after the addInFlight
        sendPubAck(new PubAckEvent(messageID, clientID));
        LOG.debug("replying with PubAck to MSG ID {}", messageID);
    } else if (qos == AbstractMessage.QOSType.EXACTLY_ONCE) {
        String publishKey = String.format("%s%d", clientID, messageID);
        //store the message in temp store
        PublishEvent qos2Persistent = new PublishEvent(topic, qos, message, retain, clientID, messageID);
        m_messagesStore.persistQoS2Message(publishKey, qos2Persistent);
        sendPubRec(clientID, messageID);
        //Next the client will send us a pub rel
        //NB publish to subscribers for QoS 2 happen upon PUBREL from publisher
    }
    if (retain) {
        if (qos == AbstractMessage.QOSType.MOST_ONE) {
            //QoS == 0 && retain => clean old retained
            m_messagesStore.cleanRetained(topic);
        } else {
            m_messagesStore.storeRetained(topic, message, qos);
        }
    }
}

[Buggy Hunk]
LOG.info("PUBLISH from clientID [{}] on topic [{}] with QoS {} content[{}]", clientID, topic, qos, DebugUtils.payload2Str(message));

[Patch]
LOG.info("PUBLISH from clientID [{}] on topic [{}] with QoS [{}]", clientID, topic, qos);