Program: 104494
Project: 104494
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);
  if (!Constants.TABBED_CHAT_WINDOW) {
    if (contactMsgWindows.containsKey(metaContact)) {
      ChatWindow msgWindow=(ChatWindow)contactMsgWindows.get(metaContact);
      msgWindow.getCurrentChatPanel().processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (msgWindow.getState() == JFrame.ICONIFIED) {
        msgWindow.setTitle(msgWindow.getTitle() + "String_Node_Str");
      }
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        msgWindow.setVisible(true);
      }
    }
 else {
      ChatWindow msgWindow=new ChatWindow(mainFrame);
      contactMsgWindows.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 (tabbedChatWindow == null) {
      tabbedChatWindow=new ChatWindow(mainFrame);
      tabbedChatWindow.addWindowListener(new WindowAdapter(){
        public void windowClosing(        WindowEvent e){
          tabbedChatWindow=null;
        }
      }
);
    }
    Hashtable contactTabsTable=tabbedChatWindow.getContactChatsTable();
    ChatPanel chatPanel;
    if (contactTabsTable.get(metaContact.getMetaUID()) == null) {
      chatPanel=tabbedChatWindow.createChat(metaContact,contactStatus,protocolContact);
      chatPanel.loadHistory(message.getMessageUID());
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        tabbedChatWindow.addChatTab(chatPanel);
        tabbedChatWindow.setVisible(true);
        chatPanel.setCaretToEnd();
        tabbedChatWindow.getCurrentChatPanel().requestFocusInWriteArea();
        if (tabbedChatWindow.getTabCount() > 1) {
          tabbedChatWindow.highlightTab(metaContact);
        }
      }
    }
 else {
      chatPanel=tabbedChatWindow.getChatPanel(metaContact);
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (tabbedChatWindow.getState() == JFrame.ICONIFIED) {
        if (tabbedChatWindow.getTabCount() > 1) {
          tabbedChatWindow.setSelectedContactTab(metaContact);
        }
        if (!tabbedChatWindow.getTitle().endsWith("String_Node_Str")) {
          tabbedChatWindow.setTitle(tabbedChatWindow.getTitle() + "String_Node_Str");
        }
      }
 else {
        if (tabbedChatWindow.getTabCount() > 1) {
          tabbedChatWindow.highlightTab(metaContact);
        }
        tabbedChatWindow.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);
  if (!Constants.TABBED_CHAT_WINDOW) {
    if (contactMsgWindows.containsKey(metaContact)) {
      ChatWindow msgWindow=(ChatWindow)contactMsgWindows.get(metaContact);
      msgWindow.getCurrentChatPanel().processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (msgWindow.getState() == JFrame.ICONIFIED) {
        msgWindow.setTitle("String_Node_Str" + msgWindow.getTitle());
      }
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        if (msgWindow.isVisible())         msgWindow.toFront();
 else         msgWindow.setVisible(true);
      }
    }
 else {
      ChatWindow msgWindow=new ChatWindow(mainFrame);
      contactMsgWindows.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 (tabbedChatWindow == null) {
      tabbedChatWindow=new ChatWindow(mainFrame);
      tabbedChatWindow.addWindowListener(new WindowAdapter(){
        public void windowClosing(        WindowEvent e){
          tabbedChatWindow=null;
        }
      }
);
    }
    Hashtable contactTabsTable=tabbedChatWindow.getContactChatsTable();
    ChatPanel chatPanel;
    if (contactTabsTable.get(metaContact.getMetaUID()) == null) {
      chatPanel=tabbedChatWindow.createChat(metaContact,contactStatus,protocolContact);
      chatPanel.loadHistory(message.getMessageUID());
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (Constants.AUTO_POPUP_NEW_MESSAGE) {
        tabbedChatWindow.addChatTab(chatPanel);
        if (tabbedChatWindow.isVisible())         tabbedChatWindow.toFront();
 else         tabbedChatWindow.setVisible(true);
        chatPanel.setCaretToEnd();
        tabbedChatWindow.getCurrentChatPanel().requestFocusInWriteArea();
        if (tabbedChatWindow.getTabCount() > 1) {
          tabbedChatWindow.highlightTab(metaContact);
        }
      }
    }
 else {
      chatPanel=tabbedChatWindow.getChatPanel(metaContact);
      chatPanel.processMessage(protocolContact.getDisplayName(),date,Constants.INCOMING_MESSAGE,message.getContent());
      if (tabbedChatWindow.getState() == JFrame.ICONIFIED) {
        if (tabbedChatWindow.getTabCount() > 1) {
          tabbedChatWindow.setSelectedContactTab(metaContact);
        }
        if (!tabbedChatWindow.getTitle().startsWith("String_Node_Str")) {
          tabbedChatWindow.setTitle("String_Node_Str" + tabbedChatWindow.getTitle());
        }
      }
 else {
        if (tabbedChatWindow.getTabCount() > 1) {
          tabbedChatWindow.highlightTab(metaContact);
        }
        if (tabbedChatWindow.isVisible())         tabbedChatWindow.toFront();
 else         tabbedChatWindow.setVisible(true);
      }
    }
  }
  if (Constants.AUTO_POPUP_NEW_MESSAGE)   Constants.getDefaultMessageAudio().play();
}