Program: 140139
Project: 140139
Buggy source:
private void addMouseListenerForChart(final ChartPanel chartPanel,final EIndicatorChartType chartType,final Analysis analysis){
  chartPanel.addChartMouseListener(new ChartMouseListener(){
    public void chartMouseClicked(    ChartMouseEvent event){
      ChartEntity chartEntity=event.getEntity();
      if (chartEntity != null) {
        CategoryItemEntity cateEntity=(CategoryItemEntity)chartEntity;
        IDataEntity dataEntity=(IDataEntity)cateEntity.getDataset();
        ChartDataEntity currentDataEntity=null;
        ChartDataEntity[] dataEntities=dataEntity.getDataEntities();
        if (dataEntities.length == 1) {
          currentDataEntity=dataEntities[0];
        }
 else {
          for (          ChartDataEntity entity : dataEntities) {
switch (chartType) {
case FREQUENCE_STATISTICS:
case LOW_FREQUENCE_STATISTICS:
case PATTERN_FREQUENCE_STATISTICS:
case PATTERN_LOW_FREQUENCE_STATISTICS:
              if (cateEntity.getColumnKey().compareTo(entity.getLabel()) == 0) {
                currentDataEntity=entity;
              }
            break;
default :
          if (cateEntity.getRowKey().compareTo(entity.getLabel()) == 0) {
            currentDataEntity=entity;
          }
      }
    }
  }
  PopupMenu menu=new PopupMenu(DefaultMessagesImpl.getString("String_Node_Str"));
  if (currentDataEntity != null) {
    final Indicator currentIndicator=currentDataEntity.getIndicator();
    int createPatternFlag=0;
    MenuItemEntity[] itemEntities=ChartTableMenuGenerator.generate(chartType,analysis,currentDataEntity);
    for (    final MenuItemEntity itemEntity : itemEntities) {
      MenuItem item=new MenuItem(itemEntity.getLabel());
      item.addActionListener(new ActionListener(){
        public void actionPerformed(        ActionEvent arg0){
          Display.getDefault().asyncExec(new Runnable(){
            public void run(){
              ChartTableFactory.viewRecordInDataExplorer(analysis,currentIndicator,itemEntity.getQuery());
            }
          }
);
        }
      }
);
      menu.add(item);
      if (createPatternFlag == 0) {
        MenuItem itemCreatePatt=new MenuItem("String_Node_Str");
        final PatternTransformer pattTransformer=new PatternTransformer(DbmsLanguageFactory.createDbmsLanguage(analysis));
        itemCreatePatt.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent e){
            Display.getDefault().asyncExec(new Runnable(){
              public void run(){
                ChartTableFactory.createPattern(analysis,itemEntity,pattTransformer);
              }
            }
);
          }
        }
);
        menu.add(itemCreatePatt);
      }
    }
    chartPanel.add(menu);
    menu.show(chartPanel,event.getTrigger().getX(),event.getTrigger().getY());
    createPatternFlag++;
  }
}
}
public void chartMouseMoved(ChartMouseEvent event){
}
}
);
}

Fixed version (ground truth):
private void addMouseListenerForChart(final ChartPanel chartPanel,final EIndicatorChartType chartType,final Analysis analysis){
  chartPanel.addChartMouseListener(new ChartMouseListener(){
    public void chartMouseClicked(    ChartMouseEvent event){
      ChartEntity chartEntity=event.getEntity();
      if (chartEntity != null) {
        CategoryItemEntity cateEntity=(CategoryItemEntity)chartEntity;
        IDataEntity dataEntity=(IDataEntity)cateEntity.getDataset();
        ChartDataEntity currentDataEntity=null;
        ChartDataEntity[] dataEntities=dataEntity.getDataEntities();
        if (dataEntities.length == 1) {
          currentDataEntity=dataEntities[0];
        }
 else {
          for (          ChartDataEntity entity : dataEntities) {
switch (chartType) {
case FREQUENCE_STATISTICS:
case LOW_FREQUENCE_STATISTICS:
case PATTERN_FREQUENCE_STATISTICS:
case PATTERN_LOW_FREQUENCE_STATISTICS:
              if (cateEntity.getColumnKey().compareTo(entity.getLabel()) == 0) {
                currentDataEntity=entity;
              }
            break;
default :
          if (cateEntity.getRowKey().compareTo(entity.getLabel()) == 0) {
            currentDataEntity=entity;
          }
      }
    }
  }
  PopupMenu menu=new PopupMenu(DefaultMessagesImpl.getString("String_Node_Str"));
  if (currentDataEntity != null) {
    final Indicator currentIndicator=currentDataEntity.getIndicator();
    int createPatternFlag=0;
    MenuItemEntity[] itemEntities=ChartTableMenuGenerator.generate(chartType,analysis,currentDataEntity);
    for (    final MenuItemEntity itemEntity : itemEntities) {
      MenuItem item=new MenuItem(itemEntity.getLabel());
      item.addActionListener(new ActionListener(){
        public void actionPerformed(        ActionEvent arg0){
          Display.getDefault().asyncExec(new Runnable(){
            public void run(){
              ChartTableFactory.viewRecordInDataExplorer(analysis,currentIndicator,itemEntity.getQuery());
            }
          }
);
        }
      }
);
      menu.add(item);
      if ((currentIndicator instanceof PatternFreqIndicator || currentIndicator instanceof PatternLowFreqIndicator) && createPatternFlag == 0) {
        MenuItem itemCreatePatt=new MenuItem("String_Node_Str");
        final PatternTransformer pattTransformer=new PatternTransformer(DbmsLanguageFactory.createDbmsLanguage(analysis));
        itemCreatePatt.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent e){
            Display.getDefault().asyncExec(new Runnable(){
              public void run(){
                ChartTableFactory.createPattern(analysis,itemEntity,pattTransformer);
              }
            }
);
          }
        }
);
        menu.add(itemCreatePatt);
      }
    }
    chartPanel.add(menu);
    menu.show(chartPanel,event.getTrigger().getX(),event.getTrigger().getY());
    createPatternFlag++;
  }
}
}
public void chartMouseMoved(ChartMouseEvent event){
}
}
);
}