Program: 27399
Project: 27399
Buggy source:
public void processConnect(ServerChannel session,ConnectMessage msg){
  LOG.debug("String_Node_Str",msg.getClientID());
  if (msg.getProtocolVersion() != VERSION_3_1 && msg.getProtocolVersion() != 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);
    m_interceptor.notifyClientConnected(msg);
    return;
  }
  if (msg.isUserFlag()) {
    byte[] 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;
  }
  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.valueOf(msg.getWillQos());
    byte[] willPayload=msg.getWillMessage();
    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);
  }
  subscriptions.activate(msg.getClientID());
  if (msg.isCleanSession()) {
    cleanSession(msg.getClientID());
  }
  ConnAckMessage okResp=new ConnAckMessage();
  okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
  boolean isSessionAlreadyStored=m_sessionsStore.contains(msg.getClientID());
  if (!msg.isCleanSession() && isSessionAlreadyStored) {
    okResp.setSessionPresent(true);
  }
  session.write(okResp);
  m_interceptor.notifyClientConnected(msg);
  if (!isSessionAlreadyStored) {
    LOG.info("String_Node_Str",msg.getClientID());
    m_sessionsStore.createNewSession(msg.getClientID());
  }
  LOG.info("String_Node_Str",msg.getClientID(),msg.isCleanSession());
  if (!msg.isCleanSession()) {
    republishStoredInSession(msg.getClientID());
  }
}

Fixed version (ground truth):
public void processConnect(ServerChannel session,ConnectMessage msg){
  LOG.debug("String_Node_Str",msg.getClientID());
  if (msg.getProtocolVersion() != VERSION_3_1 && msg.getProtocolVersion() != 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);
    m_interceptor.notifyClientConnected(msg);
    return;
  }
  if (msg.isUserFlag()) {
    byte[] 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;
  }
  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.setAttribute(NettyChannel.ATTR_KEY_SESSION_STOLEN,true);
    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.valueOf(msg.getWillQos());
    byte[] willPayload=msg.getWillMessage();
    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);
  }
  subscriptions.activate(msg.getClientID());
  if (msg.isCleanSession()) {
    cleanSession(msg.getClientID());
  }
  ConnAckMessage okResp=new ConnAckMessage();
  okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
  boolean isSessionAlreadyStored=m_sessionsStore.contains(msg.getClientID());
  if (!msg.isCleanSession() && isSessionAlreadyStored) {
    okResp.setSessionPresent(true);
  }
  session.write(okResp);
  m_interceptor.notifyClientConnected(msg);
  if (!isSessionAlreadyStored) {
    LOG.info("String_Node_Str",msg.getClientID());
    m_sessionsStore.createNewSession(msg.getClientID());
  }
  LOG.info("String_Node_Str",msg.getClientID(),msg.isCleanSession());
  if (!msg.isCleanSession()) {
    republishStoredInSession(msg.getClientID());
  }
}