Program: 46493
Project: 46493
Buggy source:
/** 
 * Shows the popup menu for the given tab.
 * @param parent parent which the popup menu belongs to
 * @param event mouse event with the coordinates
 * @param h vmId of the virtual machine
 * @param tabIndex the index of the tab
 */
private void showTabPopupMenu(final Component parent,final MouseEvent event,final VmHandle h,final int tabIndex){
  LOG.debug("String_Node_Str",h);
  if (h == null)   return;
  ResourceBundle resourceBundle=I18nBundleProvider.getBundle();
  VmState state=vmMon.getVmState(h);
  vmPopupMenu=new JPopupMenu();
switch (state) {
case STOPPED:
    vmPopupMenu.add(new VmStartAction(h));
  vmPopupMenu.add(new VmDeleteAction(h));
break;
case RUNNING:
vmPopupMenu.add(new VmSaveAction(h));
vmPopupMenu.add(new VmPoweroffAction(h));
vmPopupMenu.addSeparator();
vmPopupMenu.add(new VmInstallAdditionsAction(h));
JideMenu usbMenu=new JideMenu(I18nBundleProvider.getBundle().getString("String_Node_Str"));
vmPopupMenu.add(usbMenu);
populateUsbMenu(h,usbMenu);
if (vmMon.getVmClassification(h) == CubeClassification.UNCLASSIFIED) {
JMenu nicMenu=new JMenu(I18nBundleProvider.getBundle().getString("String_Node_Str"));
vmPopupMenu.add(nicMenu);
populateNicMenu(h,nicMenu);
}
break;
case STAGABLE:
vmPopupMenu.add(new VmStageAction(h));
break;
case STAGING:
vmPopupMenu.add(new VmStageAction(h,false));
break;
case STARTING:
case STOPPING:
vmPopupMenu.add(new VmSaveAction(h,false));
vmPopupMenu.add(new VmPoweroffAction(h,false));
break;
case ERROR:
case UNKNOWN:
vmPopupMenu.add(new VmPoweroffAction(h));
vmPopupMenu.add(new VmDeleteAction(h));
break;
default :
LOG.error("String_Node_Str" + state + "String_Node_Str");
return;
}
if (state == VmState.RUNNING) {
}
if (state == VmState.STOPPED || state == VmState.STAGABLE) {
vmPopupMenu.addSeparator();
vmPopupMenu.add(new VmHideAction(h,false));
}
List<CubeScreen> screens=cubeUI.getScreens();
if (screens.size() > 1) {
vmPopupMenu.addSeparator();
JideMenu monitorMenu=new JideMenu(resourceBundle.getString("String_Node_Str"));
vmPopupMenu.add(monitorMenu);
for (CubeScreen c : screens) {
if (!c.getId().equals(monitorId) && c.isActive()) {
final String destMonitorId=c.getId();
JMenuItem item=new JMenuItem(MessageFormat.format(resourceBundle.getString("String_Node_Str"),destMonitorId));
item.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e){
vmCtrl.moveVm(h,destMonitorId);
}
}
);
monitorMenu.add(item);
}
}
}
LOG.debug("String_Node_Str",event.getX(),event.getY());
JComponent comp=(JComponent)event.getSource();
vmPopupMenu.show(parent,event.getX(),event.getY());
}

Fixed version (ground truth):
/** 
 * Shows the popup menu for the given tab.
 * @param parent parent which the popup menu belongs to
 * @param event mouse event with the coordinates
 * @param h vmId of the virtual machine
 * @param tabIndex the index of the tab
 */
private void showTabPopupMenu(final Component parent,final MouseEvent event,final VmHandle h,final int tabIndex){
  LOG.debug("String_Node_Str",h);
  if (h == null)   return;
  ResourceBundle resourceBundle=I18nBundleProvider.getBundle();
  VmState state=vmMon.getVmState(h);
  vmPopupMenu=new JPopupMenu();
switch (state) {
case STOPPED:
    vmPopupMenu.add(new VmStartAction(h));
  vmPopupMenu.add(new VmDeleteAction(h));
break;
case RUNNING:
vmPopupMenu.add(new VmSaveAction(h));
vmPopupMenu.add(new VmPoweroffAction(h));
vmPopupMenu.addSeparator();
vmPopupMenu.add(new VmInstallAdditionsAction(h));
JideMenu usbMenu=new JideMenu(I18nBundleProvider.getBundle().getString("String_Node_Str"));
vmPopupMenu.add(usbMenu);
populateUsbMenu(h,usbMenu);
if (vmMon.getVmClassification(h) == CubeClassification.UNCLASSIFIED) {
JMenu nicMenu=new JMenu(I18nBundleProvider.getBundle().getString("String_Node_Str"));
vmPopupMenu.add(nicMenu);
populateNicMenu(h,nicMenu);
}
break;
case STAGABLE:
vmPopupMenu.add(new VmStageAction(h));
break;
case STAGING:
vmPopupMenu.add(new VmStageAction(h,false));
break;
case STARTING:
case STOPPING:
vmPopupMenu.add(new VmSaveAction(h,false));
vmPopupMenu.add(new VmPoweroffAction(h,false));
break;
case ERROR:
case UNKNOWN:
vmPopupMenu.add(new VmPoweroffAction(h));
vmPopupMenu.add(new VmDeleteAction(h));
break;
default :
LOG.error("String_Node_Str" + state + "String_Node_Str");
return;
}
if (state == VmState.RUNNING) {
}
if (state == VmState.STOPPED || state == VmState.STAGABLE) {
vmPopupMenu.addSeparator();
vmPopupMenu.add(new VmHideAction(h,false));
}
List<CubeScreen> screens=cubeUI.getScreens();
if (screens.size() > 1) {
vmPopupMenu.addSeparator();
JideMenu monitorMenu=new JideMenu(resourceBundle.getString("String_Node_Str"));
vmPopupMenu.add(monitorMenu);
for (CubeScreen c : screens) {
if (!c.getId().equals(monitorId) && c.isActive()) {
final String destMonitorId=c.getId();
JMenuItem item=new JMenuItem(MessageFormat.format(resourceBundle.getString("String_Node_Str"),destMonitorId));
item.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e){
vmCtrl.moveVm(h,destMonitorId);
}
}
);
monitorMenu.add(item);
}
}
}
LOG.debug("String_Node_Str",event.getXOnScreen(),event.getYOnScreen());
LOG.debug("String_Node_Str",event.getX(),event.getY());
JComponent comp=(JComponent)event.getSource();
vmPopupMenu.show(parent,event.getXOnScreen(),event.getYOnScreen());
}