Program: 27413
Project: 27413
Buggy source:
@MQTTMessage(message=ConnectMessage.class) void processConnect(ServerChannel session,ConnectMessage msg){
  LOG.debug("String_Node_Str",msg.getClientID());
  if (msg.getProcotolVersion() != VERSION_3_1 && msg.getProcotolVersion() != VERSION_3_1_1) {
    ConnAckMessage badProto=new ConnAckMessage();
    badProto.setReturnCode(ConnAckMessage.UNNACEPTABLE_PROTOCOL_VERSION);
    LOG.warn("String_Node_Str");
    session.write(badProto);
    session.close(false);
    return;
  }
  if (msg.getClientID() == null || msg.getClientID().length() == 0) {
    ConnAckMessage okResp=new ConnAckMessage();
    okResp.setReturnCode(ConnAckMessage.IDENTIFIER_REJECTED);
    session.write(okResp);
    return;
  }
  if (m_clientIDs.containsKey(msg.getClientID())) {
    LOG.info("String_Node_Str",msg.getClientID());
    ServerChannel oldSession=m_clientIDs.get(msg.getClientID()).getSession();
    boolean cleanSession=(Boolean)oldSession.getAttribute(NettyChannel.ATTR_KEY_CLEANSESSION);
    if (cleanSession) {
      cleanSession(msg.getClientID());
    }
    oldSession.close(false);
    LOG.debug("String_Node_Str",msg.getClientID());
  }
  ConnectionDescriptor connDescr=new ConnectionDescriptor(msg.getClientID(),session,msg.isCleanSession());
  m_clientIDs.put(msg.getClientID(),connDescr);
  int keepAlive=msg.getKeepAlive();
  LOG.debug("String_Node_Str",keepAlive);
  session.setAttribute(NettyChannel.ATTR_KEY_KEEPALIVE,keepAlive);
  session.setAttribute(NettyChannel.ATTR_KEY_CLEANSESSION,msg.isCleanSession());
  session.setAttribute(NettyChannel.ATTR_KEY_CLIENTID,msg.getClientID());
  LOG.debug("String_Node_Str",session);
  session.setIdleTime(Math.round(keepAlive * 1.5f));
  if (msg.isWillFlag()) {
    AbstractMessage.QOSType willQos=AbstractMessage.QOSType.values()[msg.getWillQos()];
    byte[] willPayload=msg.getWillMessage().getBytes();
    ByteBuffer bb=(ByteBuffer)ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
    WillMessage will=new WillMessage(msg.getWillTopic(),bb,msg.isWillRetain(),willQos);
    m_willStore.put(msg.getClientID(),will);
  }
  if (msg.isUserFlag()) {
    String pwd=null;
    if (msg.isPasswordFlag()) {
      pwd=msg.getPassword();
    }
 else     if (!this.allowAnonymous) {
      failedCredetials(session);
      return;
    }
    if (!m_authenticator.checkValid(msg.getUsername(),pwd)) {
      failedCredetials(session);
      return;
    }
    session.setAttribute(NettyChannel.ATTR_KEY_USERNAME,msg.getUsername());
  }
 else   if (!this.allowAnonymous) {
    failedCredetials(session);
    return;
  }
  subscriptions.activate(msg.getClientID());
  if (msg.isCleanSession()) {
    cleanSession(msg.getClientID());
  }
  ConnAckMessage okResp=new ConnAckMessage();
  okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
  if (!msg.isCleanSession() && m_sessionsStore.contains(msg.getClientID())) {
    okResp.setSessionPresent(true);
  }
  session.write(okResp);
  LOG.info("String_Node_Str",msg.getClientID());
  m_sessionsStore.addNewSubscription(Subscription.createEmptySubscription(msg.getClientID(),true),msg.getClientID());
  LOG.info("String_Node_Str",msg.getClientID(),msg.isCleanSession());
  if (!msg.isCleanSession()) {
    republishStoredInSession(msg.getClientID());
  }
}

Fixed version (ground truth):
@MQTTMessage(message=ConnectMessage.class) void processConnect(ServerChannel session,ConnectMessage msg){
  LOG.debug("String_Node_Str",msg.getClientID());
  if (msg.getProcotolVersion() != VERSION_3_1 && msg.getProcotolVersion() != VERSION_3_1_1) {
    ConnAckMessage badProto=new ConnAckMessage();
    badProto.setReturnCode(ConnAckMessage.UNNACEPTABLE_PROTOCOL_VERSION);
    LOG.warn("String_Node_Str");
    session.write(badProto);
    session.close(false);
    return;
  }
  if (msg.getClientID() == null || msg.getClientID().length() == 0) {
    ConnAckMessage okResp=new ConnAckMessage();
    okResp.setReturnCode(ConnAckMessage.IDENTIFIER_REJECTED);
    session.write(okResp);
    return;
  }
  if (m_clientIDs.containsKey(msg.getClientID())) {
    LOG.info("String_Node_Str",msg.getClientID());
    ServerChannel oldSession=m_clientIDs.get(msg.getClientID()).getSession();
    boolean cleanSession=(Boolean)oldSession.getAttribute(NettyChannel.ATTR_KEY_CLEANSESSION);
    if (cleanSession) {
      cleanSession(msg.getClientID());
    }
    oldSession.close(false);
    LOG.debug("String_Node_Str",msg.getClientID());
  }
  ConnectionDescriptor connDescr=new ConnectionDescriptor(msg.getClientID(),session,msg.isCleanSession());
  m_clientIDs.put(msg.getClientID(),connDescr);
  int keepAlive=msg.getKeepAlive();
  LOG.debug("String_Node_Str",keepAlive);
  session.setAttribute(NettyChannel.ATTR_KEY_KEEPALIVE,keepAlive);
  session.setAttribute(NettyChannel.ATTR_KEY_CLEANSESSION,msg.isCleanSession());
  session.setAttribute(NettyChannel.ATTR_KEY_CLIENTID,msg.getClientID());
  LOG.debug("String_Node_Str",session);
  session.setIdleTime(Math.round(keepAlive * 1.5f));
  if (msg.isWillFlag()) {
    AbstractMessage.QOSType willQos=AbstractMessage.QOSType.values()[msg.getWillQos()];
    byte[] willPayload=msg.getWillMessage().getBytes();
    ByteBuffer bb=(ByteBuffer)ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
    WillMessage will=new WillMessage(msg.getWillTopic(),bb,msg.isWillRetain(),willQos);
    m_willStore.put(msg.getClientID(),will);
  }
  if (msg.isUserFlag()) {
    String pwd=null;
    if (msg.isPasswordFlag()) {
      pwd=msg.getPassword();
    }
 else     if (!this.allowAnonymous) {
      failedCredentials(session);
      return;
    }
    if (!m_authenticator.checkValid(msg.getUsername(),pwd)) {
      failedCredentials(session);
      return;
    }
    session.setAttribute(NettyChannel.ATTR_KEY_USERNAME,msg.getUsername());
  }
 else   if (!this.allowAnonymous) {
    failedCredentials(session);
    return;
  }
  subscriptions.activate(msg.getClientID());
  if (msg.isCleanSession()) {
    cleanSession(msg.getClientID());
  }
  ConnAckMessage okResp=new ConnAckMessage();
  okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
  if (!msg.isCleanSession() && m_sessionsStore.contains(msg.getClientID())) {
    okResp.setSessionPresent(true);
  }
  session.write(okResp);
  LOG.info("String_Node_Str",msg.getClientID());
  m_sessionsStore.addNewSubscription(Subscription.createEmptySubscription(msg.getClientID(),true),msg.getClientID());
  LOG.info("String_Node_Str",msg.getClientID(),msg.isCleanSession());
  if (!msg.isCleanSession()) {
    republishStoredInSession(msg.getClientID());
  }
}