Program: 104483
Project: 104483
Buggy source:
/** 
 * When a message is received determines whether to open a new chat window or chat window tab, or to indicate that a message is received from a contact which already has an open chat. When the chat is found checks if in mode "Auto popup enabled" and if this is the case shows the message in the appropriate chat panel.
 * @param evt the event containing details on the received message
 */
public void messageReceived(MessageReceivedEvent evt){
  Contact protocolContact=evt.getSourceContact();
  Date date=evt.getTimestamp();
  Message message=evt.getSourceMessage();
  MetaContact metaContact=mainFrame.getContactList().findMetaContactByContact(protocolContact);
  PresenceStatus contactStatus=((ContactListModel)this.contactList.getModel()).getMetaContactStatus(metaContact);
  ChatWindow chatWindow;
  if (!Constants.TABBED_CHAT_WINDOW) {
    if (chatWindows.containsKey(metaContact)) {
      chatWindow=(ChatWindow)chatWindows.get(metaContact);
      chatWindow.getCurrentChatPanel().processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (chatWindow.getState() == JFrame.ICONIFIED) {
        chatWindow.setTitle("String_Node_Str" + chatWindow.getTitle());
      }
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        if (chatWindow.isVisible()) {
          if (chatWindow.getState() == JFrame.ICONIFIED)           chatWindow.setState(JFrame.NORMAL);
          chatWindow.toFront();
        }
 else         chatWindow.setVisible(true);
      }
    }
 else {
      ChatWindow msgWindow=new ChatWindow(mainFrame);
      chatWindows.put(metaContact,msgWindow);
      ChatPanel chatPanel=msgWindow.createChat(metaContact,contactStatus,protocolContact);
      chatPanel.loadHistory(message.getMessageUID());
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        msgWindow.addChat(chatPanel);
        msgWindow.pack();
        msgWindow.setVisible(true);
        chatPanel.setCaretToEnd();
      }
    }
  }
 else {
    if (chatWindows.isEmpty()) {
      chatWindow=new ChatWindow(mainFrame);
    }
 else {
      chatWindow=(ChatWindow)chatWindows.elements().nextElement();
    }
    ChatPanel chatPanel;
    if (!chatWindow.containsContactChat(metaContact)) {
      chatPanel=chatWindow.createChat(metaContact,contactStatus,protocolContact);
      chatPanel.loadHistory(message.getMessageUID());
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        chatWindow.addChatTab(chatPanel);
        if (chatWindow.isVisible()) {
          if (chatWindow.getState() == JFrame.ICONIFIED)           chatWindow.setState(JFrame.NORMAL);
          chatWindow.toFront();
        }
 else         chatWindow.setVisible(true);
        chatPanel.setCaretToEnd();
        chatWindow.getCurrentChatPanel().requestFocusInWriteArea();
        if (chatWindow.getTabCount() > 1) {
          chatWindow.highlightTab(metaContact);
        }
      }
    }
 else {
      chatPanel=chatWindow.getChatPanel(metaContact);
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (chatWindow.getState() == JFrame.ICONIFIED) {
        if (chatWindow.getTabCount() > 1) {
          chatWindow.setSelectedContactTab(metaContact);
        }
        if (!chatWindow.getTitle().startsWith("String_Node_Str")) {
          chatWindow.setTitle("String_Node_Str" + chatWindow.getTitle());
        }
      }
 else {
        if (chatWindow.getTabCount() > 1) {
          chatWindow.highlightTab(metaContact);
        }
        if (chatWindow.isVisible())         chatWindow.toFront();
 else         chatWindow.setVisible(true);
      }
    }
  }
  if (Constants.AUTO_POPUP_NEW_MESSAGE)   Constants.getDefaultMessageAudio().play();
}

Fixed version (ground truth):
/** 
 * When a message is received determines whether to open a new chat window or chat window tab, or to indicate that a message is received from a contact which already has an open chat. When the chat is found checks if in mode "Auto popup enabled" and if this is the case shows the message in the appropriate chat panel.
 * @param evt the event containing details on the received message
 */
public void messageReceived(MessageReceivedEvent evt){
  Contact protocolContact=evt.getSourceContact();
  Date date=evt.getTimestamp();
  Message message=evt.getSourceMessage();
  MetaContact metaContact=mainFrame.getContactList().findMetaContactByContact(protocolContact);
  PresenceStatus contactStatus=((ContactListModel)this.contactList.getModel()).getMetaContactStatus(metaContact);
  ChatWindow chatWindow;
  if (!Constants.TABBED_CHAT_WINDOW) {
    if (chatWindows.containsKey(metaContact)) {
      chatWindow=(ChatWindow)chatWindows.get(metaContact);
      chatWindow.getCurrentChatPanel().processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (chatWindow.getState() == JFrame.ICONIFIED) {
        chatWindow.setTitle("String_Node_Str" + chatWindow.getTitle());
      }
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        if (chatWindow.isVisible()) {
          if (chatWindow.getState() == JFrame.ICONIFIED)           chatWindow.setState(JFrame.NORMAL);
          chatWindow.toFront();
        }
 else         chatWindow.setVisible(true);
      }
    }
 else {
      ChatWindow msgWindow=new ChatWindow(mainFrame);
      chatWindows.put(metaContact,msgWindow);
      ChatPanel chatPanel=msgWindow.createChat(metaContact,contactStatus,protocolContact);
      chatPanel.loadHistory(message.getMessageUID());
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        msgWindow.addChat(chatPanel);
        msgWindow.pack();
        msgWindow.setVisible(true);
        chatPanel.setCaretToEnd();
      }
    }
  }
 else {
    if (chatWindows.isEmpty()) {
      chatWindow=new ChatWindow(mainFrame);
      chatWindows.put(metaContact,chatWindow);
    }
 else {
      chatWindow=(ChatWindow)chatWindows.elements().nextElement();
    }
    ChatPanel chatPanel;
    if (!chatWindow.containsContactChat(metaContact)) {
      chatPanel=chatWindow.createChat(metaContact,contactStatus,protocolContact);
      chatPanel.loadHistory(message.getMessageUID());
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        chatWindow.addChatTab(chatPanel);
        if (chatWindow.isVisible()) {
          if (chatWindow.getState() == JFrame.ICONIFIED)           chatWindow.setState(JFrame.NORMAL);
          chatWindow.toFront();
        }
 else         chatWindow.setVisible(true);
        chatPanel.setCaretToEnd();
        chatWindow.getCurrentChatPanel().requestFocusInWriteArea();
        if (chatWindow.getTabCount() > 1) {
          chatWindow.highlightTab(metaContact);
        }
      }
    }
 else {
      chatPanel=chatWindow.getChatPanel(metaContact);
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (chatWindow.getState() == JFrame.ICONIFIED) {
        if (chatWindow.getTabCount() > 1) {
          chatWindow.setSelectedContactTab(metaContact);
        }
        if (!chatWindow.getTitle().startsWith("String_Node_Str")) {
          chatWindow.setTitle("String_Node_Str" + chatWindow.getTitle());
        }
      }
 else {
        if (chatWindow.getTabCount() > 1) {
          chatWindow.highlightTab(metaContact);
        }
        if (chatWindow.isVisible())         chatWindow.toFront();
 else         chatWindow.setVisible(true);
      }
    }
  }
  if (Constants.AUTO_POPUP_NEW_MESSAGE)   Constants.getDefaultMessageAudio().play();
}