Program: 104593
Project: 104593
Buggy source:
/** 
 * Creates a ChatPanel for the given contact and adds it to a tabbedPane.
 * @param contact The MetaContact added to the chat.
 */
public void addChatTab(MetaContact contact,PresenceStatus status){
  OperationSetBasicInstantMessaging contactIMOperationSet=this.mainFrame.getProtocolIM(contact.getDefaultContact().getProtocolProvider());
  if (chatTabbedPane == null) {
    this.setCurrentChatPanel(new ChatPanel(this,contactIMOperationSet));
    this.currentChatPanel.addContactToChat(contact,status);
    chatTabbedPane=new SIPCommTabbedPane(true);
    chatTabbedPane.addCloseListener(new CloseListener(){
      public void closeOperation(      MouseEvent e){
        int selectedIndex=chatTabbedPane.getOverTabIndex();
        removeContactTab(selectedIndex);
      }
    }
);
    chatTabbedPane.addChangeListener(new ChangeListener(){
      public void stateChanged(      ChangeEvent e){
        ChatPanel chatPanel=(ChatPanel)chatTabbedPane.getSelectedComponent();
        if (chatPanel != null) {
          setTitle(chatPanel.getDefaultContact().getDisplayName());
          setCurrentChatPanel(chatPanel);
        }
      }
    }
);
    this.getContentPane().add(this.currentChatPanel,BorderLayout.CENTER);
    this.currentChatPanel.setTabIndex(0);
    this.contactTabsTable.put(contact.getDisplayName(),currentChatPanel);
    this.setTitle(contact.getDisplayName());
  }
 else {
    PresenceStatus defaultStatus=contact.getDefaultContact().getPresenceStatus();
    if (chatTabbedPane.getTabCount() > 0) {
      this.setCurrentChatPanel(new ChatPanel(this,contactIMOperationSet));
      this.currentChatPanel.addContactToChat(contact,status);
      chatTabbedPane.addTab(contact.getDisplayName(),new ImageIcon(Constants.getStatusIcon(defaultStatus)),currentChatPanel);
      chatTabbedPane.getParent().validate();
      this.currentChatPanel.setTabIndex(chatTabbedPane.getTabCount() - 1);
      this.contactTabsTable.put(contact.getDisplayName(),currentChatPanel);
    }
 else {
      PresenceStatus currentContactStatus=currentChatPanel.getDefaultContact().getDefaultContact().getPresenceStatus();
      chatTabbedPane.addTab(currentChatPanel.getDefaultContact().getDisplayName(),new ImageIcon(Constants.getStatusIcon(currentContactStatus)),currentChatPanel);
      this.setCurrentChatPanel(new ChatPanel(this,contactIMOperationSet));
      this.currentChatPanel.addContactToChat(contact,status);
      chatTabbedPane.addTab(contact.getDisplayName(),new ImageIcon(Constants.getStatusIcon(defaultStatus)),currentChatPanel);
      currentChatPanel.setTabIndex(chatTabbedPane.getTabCount() - 1);
      this.contactTabsTable.put(contact.getDisplayName(),currentChatPanel);
    }
    this.getContentPane().add(chatTabbedPane,BorderLayout.CENTER);
    this.getContentPane().validate();
  }
}

Fixed version (ground truth):
/** 
 * Creates a ChatPanel for the given contact and adds it to a tabbedPane.
 * @param contact The MetaContact added to the chat.
 */
public void addChatTab(MetaContact contact,PresenceStatus status){
  OperationSetBasicInstantMessaging contactIMOperationSet=this.mainFrame.getProtocolIM(contact.getDefaultContact().getProtocolProvider());
  if (chatTabbedPane == null) {
    this.setCurrentChatPanel(new ChatPanel(this,contactIMOperationSet));
    this.currentChatPanel.addContactToChat(contact,status);
    chatTabbedPane=new SIPCommTabbedPane(true);
    chatTabbedPane.addCloseListener(new CloseListener(){
      public void closeOperation(      MouseEvent e){
        int selectedIndex=chatTabbedPane.getOverTabIndex();
        removeContactTab(selectedIndex);
      }
    }
);
    this.getContentPane().add(this.currentChatPanel,BorderLayout.CENTER);
    this.currentChatPanel.setTabIndex(0);
    this.contactTabsTable.put(contact.getDisplayName(),currentChatPanel);
    this.setTitle(contact.getDisplayName());
  }
 else {
    PresenceStatus defaultStatus=contact.getDefaultContact().getPresenceStatus();
    if (chatTabbedPane.getTabCount() > 0) {
      this.setCurrentChatPanel(new ChatPanel(this,contactIMOperationSet));
      this.currentChatPanel.addContactToChat(contact,status);
      chatTabbedPane.addTab(contact.getDisplayName(),new ImageIcon(Constants.getStatusIcon(defaultStatus)),currentChatPanel);
      chatTabbedPane.getParent().validate();
      this.currentChatPanel.setTabIndex(chatTabbedPane.getTabCount() - 1);
      this.contactTabsTable.put(contact.getDisplayName(),currentChatPanel);
    }
 else {
      PresenceStatus currentContactStatus=currentChatPanel.getDefaultContact().getDefaultContact().getPresenceStatus();
      chatTabbedPane.addTab(currentChatPanel.getDefaultContact().getDisplayName(),new ImageIcon(Constants.getStatusIcon(currentContactStatus)),currentChatPanel);
      this.setCurrentChatPanel(new ChatPanel(this,contactIMOperationSet));
      this.currentChatPanel.addContactToChat(contact,status);
      chatTabbedPane.addTab(contact.getDisplayName(),new ImageIcon(Constants.getStatusIcon(defaultStatus)),currentChatPanel);
      currentChatPanel.setTabIndex(chatTabbedPane.getTabCount() - 1);
      this.contactTabsTable.put(contact.getDisplayName(),currentChatPanel);
    }
    this.getContentPane().add(chatTabbedPane,BorderLayout.CENTER);
    this.getContentPane().validate();
  }
}