Program: 31213
Project: 31213
Buggy source:
/** 
 * Updates the right click menu to allow for moving traces around.  Should be called right after adding a new trace.
 */
public void updateRightClickMenu(){
  popup=new JPopupMenu();
  Iterator<ITrace2D> iter=this.getTraces().iterator();
  boolean firstFlag=true;
  while (iter.hasNext()) {
    final ITrace2D trace=iter.next();
    JMenuItem topItem=new JMenuItem(trace.getName());
    topItem.setEnabled(false);
    if (!firstFlag) {
      popup.addSeparator();
    }
    popup.add(topItem);
    popup.addSeparator();
    firstFlag=false;
    boolean rightTraceFlag=false;
    for (    final AAxis axis : rightYAxis) {
      if (axis.getTraces().contains(trace)) {
        JMenuItem newItem=new JMenuItem("String_Node_Str");
        newItem.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent e){
            ZoomableChartScrollWheel.this.removeAxisYRight(axis);
            ZoomableChartScrollWheel.this.removeTrace(trace);
            ZoomableChartScrollWheel.this.addTrace(trace);
            ZoomableChartScrollWheel.this.updateRightClickMenu();
          }
        }
);
        popup.add(newItem);
        rightTraceFlag=true;
        break;
      }
    }
    if (rightTraceFlag == false) {
      JMenuItem newItem=new JMenuItem("String_Node_Str");
      if (this.getAxisY().getTraces().size() < 2) {
        newItem.setEnabled(false);
      }
      newItem.addActionListener(new ActionListener(){
        public void actionPerformed(        ActionEvent e){
          AxisLinear newAxis=new AxisLinear();
          ZoomableChartScrollWheel.this.removeTrace(trace);
          ZoomableChartScrollWheel.this.addAxisYRight(newAxis);
          ZoomableChartScrollWheel.this.addTrace(trace,ZoomableChartScrollWheel.this.getAxisX(),newAxis);
          ZoomableChartScrollWheel.this.updateRightClickMenu();
        }
      }
);
      popup.add(newItem);
    }
    JMenuItem moveWindowItem=new JMenuItem("String_Node_Str");
    moveWindowItem.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent e){
        for (        AAxis axisL : rightYAxis) {
          if (axisL.getTraces().contains(trace)) {
            ZoomableChartScrollWheel.this.removeAxisYRight(axisL);
            break;
          }
        }
        ZoomableChartScrollWheel.this.removeTrace(trace);
        ZoomableChartScrollWheel.this.updateRightClickMenu();
        JFrame frame=new JFrame(trace.getName());
        final ZoomableChartScrollWheel newChart=new ZoomableChartScrollWheel(chartData);
        trace.setColor(chartData.popColor());
        newChart.addTrace(trace);
        newChart.updateRightClickMenu();
        chartData.getCharts().add(newChart);
        Container content=frame.getContentPane();
        content.add(newChart);
        newChart.addFrameFocusTimer(frame);
        frame.addWindowListener(new WindowAdapter(){
          public void windowClosing(          WindowEvent e){
            for (            ITrace2D trace : newChart.getTraces()) {
              ((Trace2DLtd)trace).setMaxSize(chartData.sparklineChartSize);
            }
            chartData.getCharts().remove(newChart);
          }
        }
);
        frame.setSize(600,500);
        frame.setVisible(true);
      }
    }
);
    JMenuItem delItem=new JMenuItem("String_Node_Str");
    delItem.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent e){
        for (        AAxis axisL : rightYAxis) {
          if (axisL.getTraces().contains(trace)) {
            ZoomableChartScrollWheel.this.removeAxisYRight(axisL);
            break;
          }
        }
        ZoomableChartScrollWheel.this.removeTrace(trace);
        ZoomableChartScrollWheel.this.updateRightClickMenu();
      }
    }
);
    if (this.getAxisX().getTraces().size() < 2) {
      delItem.setEnabled(false);
      moveWindowItem.setEnabled(false);
    }
    popup.add(moveWindowItem);
    popup.add(delItem);
  }
}

Fixed version (ground truth):
/** 
 * Updates the right click menu to allow for moving traces around.  Should be called right after adding a new trace.
 */
public void updateRightClickMenu(){
  popup=new JPopupMenu();
  Iterator<ITrace2D> iter=this.getTraces().iterator();
  boolean firstFlag=true;
  StringBuilder frameTitle=new StringBuilder();
  while (iter.hasNext()) {
    final ITrace2D trace=iter.next();
    JMenuItem topItem=new JMenuItem(trace.getName());
    topItem.setEnabled(false);
    if (!firstFlag) {
      popup.addSeparator();
    }
    popup.add(topItem);
    popup.addSeparator();
    boolean rightTraceFlag=false;
    for (    final AAxis axis : rightYAxis) {
      if (axis.getTraces().contains(trace)) {
        JMenuItem newItem=new JMenuItem("String_Node_Str");
        newItem.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent e){
            ZoomableChartScrollWheel.this.removeAxisYRight(axis);
            ZoomableChartScrollWheel.this.removeTrace(trace);
            ZoomableChartScrollWheel.this.addTrace(trace);
            ZoomableChartScrollWheel.this.updateRightClickMenu();
          }
        }
);
        popup.add(newItem);
        rightTraceFlag=true;
        break;
      }
    }
    if (rightTraceFlag == false) {
      JMenuItem newItem=new JMenuItem("String_Node_Str");
      if (this.getAxisY().getTraces().size() < 2) {
        newItem.setEnabled(false);
      }
      newItem.addActionListener(new ActionListener(){
        public void actionPerformed(        ActionEvent e){
          AxisLinear newAxis=new AxisLinear();
          ZoomableChartScrollWheel.this.removeTrace(trace);
          ZoomableChartScrollWheel.this.addAxisYRight(newAxis);
          ZoomableChartScrollWheel.this.addTrace(trace,ZoomableChartScrollWheel.this.getAxisX(),newAxis);
          ZoomableChartScrollWheel.this.updateRightClickMenu();
        }
      }
);
      popup.add(newItem);
    }
    JMenuItem moveWindowItem=new JMenuItem("String_Node_Str");
    moveWindowItem.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent e){
        for (        AAxis axisL : rightYAxis) {
          if (axisL.getTraces().contains(trace)) {
            ZoomableChartScrollWheel.this.removeAxisYRight(axisL);
            break;
          }
        }
        ZoomableChartScrollWheel.this.removeTrace(trace);
        ZoomableChartScrollWheel.this.updateRightClickMenu();
        ZoomableChartScrollWheel.newChartFrame(chartData,trace);
      }
    }
);
    JMenuItem delItem=new JMenuItem("String_Node_Str");
    delItem.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent e){
        for (        AAxis axisL : rightYAxis) {
          if (axisL.getTraces().contains(trace)) {
            ZoomableChartScrollWheel.this.removeAxisYRight(axisL);
            break;
          }
        }
        ZoomableChartScrollWheel.this.removeTrace(trace);
        ZoomableChartScrollWheel.this.updateRightClickMenu();
      }
    }
);
    if (this.getAxisX().getTraces().size() < 2) {
      delItem.setEnabled(false);
      moveWindowItem.setEnabled(false);
    }
    popup.add(moveWindowItem);
    popup.add(delItem);
    if (!firstFlag) {
      frameTitle.append("String_Node_Str");
    }
    frameTitle.append(trace.getName());
    firstFlag=false;
  }
  if (this.frame != null) {
    this.frame.setTitle(frameTitle.toString());
  }
}