Program: 75381
Project: 75381
Buggy source:
protected void addNewSeriesDefinition(){
  SeriesDefinition sdTmp=SeriesDefinitionImpl.create();
  Palette pa=((SeriesDefinition)(seriesDefns.get(0))).getSeriesPalette();
  for (int i=0; i < pa.getEntries().size(); i++) {
    int index=i + seriesDefns.size();
    int paletteSize=pa.getEntries().size();
    while (index >= pa.getEntries().size()) {
      index-=paletteSize;
    }
    sdTmp.getSeriesPalette().getEntries().add(i,EcoreUtil.copy((Fill)pa.getEntries().get(index)));
  }
  sdTmp.getSeriesPalette().getEntries().remove(pa.getEntries().size());
  sdTmp.getSeries().add(EcoreUtil.copy(((SeriesDefinition)seriesDefns.get(0)).getDesignTimeSeries()));
  sdTmp.setQuery((Query)EcoreUtil.copy(((SeriesDefinition)seriesDefns.get(0)).getQuery()));
  cleanDataDefinition(sdTmp);
  sdTmp.eAdapters().addAll(((SeriesDefinition)seriesDefns.get(0)).eAdapters());
  int firstIndex=getFirstIndexOfSameAxis();
  EList list=getChart().getSampleData().getOrthogonalSampleData();
  OrthogonalSampleData sdOrthogonal=(OrthogonalSampleData)EcoreUtil.copy((EObject)list.get(firstIndex));
  if (axisIndex == -1) {
    sdOrthogonal.setSeriesDefinitionIndex(seriesDefns.size());
  }
 else {
    sdOrthogonal.setSeriesDefinitionIndex(ChartUIUtil.getLastSeriesIndexWithinAxis(getChart(),axisIndex) + 1);
  }
  sdOrthogonal.setDataSetRepresentation(convertDataSetRepresentation(sdOrthogonal.getDataSetRepresentation(),sdOrthogonal.getSeriesDefinitionIndex()));
  sdOrthogonal.eAdapters().addAll(getChart().getSampleData().eAdapters());
  boolean isNotificaionIgnored=ChartAdapter.isNotificationIgnored();
  ChartAdapter.ignoreNotifications(true);
  int sdIndex=sdOrthogonal.getSeriesDefinitionIndex();
  ArrayList al=new ArrayList();
  if (sdIndex >= list.size()) {
    list.add(sdOrthogonal);
  }
 else {
    for (int i=sdIndex; i < list.size(); i++) {
      al.add(list.get(i));
    }
    list.set(sdIndex,sdOrthogonal);
    for (int i=1; i < al.size(); i++) {
      list.set(i + sdIndex,al.get(i - 1));
      ((OrthogonalSampleData)list.get(i + sdIndex)).setSeriesDefinitionIndex(i + sdIndex);
    }
    list.add(al.get(al.size() - 1));
    ((OrthogonalSampleData)list.get(list.size() - 1)).setSeriesDefinitionIndex(list.size() - 1);
  }
  ChartAdapter.ignoreNotifications(isNotificaionIgnored);
  seriesDefns.add(sdTmp);
}

Fixed version (ground truth):
protected void addNewSeriesDefinition(){
  SeriesDefinition sdTmp=SeriesDefinitionImpl.create();
  if (!seriesDefns.isEmpty()) {
    Palette pa=((SeriesDefinition)(seriesDefns.get(0))).getSeriesPalette();
    for (int i=0; i < pa.getEntries().size(); i++) {
      int index=i + seriesDefns.size();
      int paletteSize=pa.getEntries().size();
      while (index >= pa.getEntries().size()) {
        index-=paletteSize;
      }
      sdTmp.getSeriesPalette().getEntries().add(i,EcoreUtil.copy((Fill)pa.getEntries().get(index)));
    }
    sdTmp.getSeriesPalette().getEntries().remove(pa.getEntries().size());
    sdTmp.getSeries().add(EcoreUtil.copy(((SeriesDefinition)seriesDefns.get(0)).getDesignTimeSeries()));
    sdTmp.setQuery((Query)EcoreUtil.copy(((SeriesDefinition)seriesDefns.get(0)).getQuery()));
    cleanDataDefinition(sdTmp);
    sdTmp.eAdapters().addAll(((SeriesDefinition)seriesDefns.get(0)).eAdapters());
    int firstIndex=getFirstIndexOfSameAxis();
    EList list=getChart().getSampleData().getOrthogonalSampleData();
    OrthogonalSampleData sdOrthogonal=(OrthogonalSampleData)EcoreUtil.copy((EObject)list.get(firstIndex));
    if (axisIndex == -1) {
      sdOrthogonal.setSeriesDefinitionIndex(seriesDefns.size());
    }
 else {
      sdOrthogonal.setSeriesDefinitionIndex(ChartUIUtil.getLastSeriesIndexWithinAxis(getChart(),axisIndex) + 1);
    }
    sdOrthogonal.setDataSetRepresentation(convertDataSetRepresentation(sdOrthogonal.getDataSetRepresentation(),sdOrthogonal.getSeriesDefinitionIndex()));
    sdOrthogonal.eAdapters().addAll(getChart().getSampleData().eAdapters());
    boolean isNotificaionIgnored=ChartAdapter.isNotificationIgnored();
    ChartAdapter.ignoreNotifications(true);
    int sdIndex=sdOrthogonal.getSeriesDefinitionIndex();
    ArrayList al=new ArrayList();
    if (sdIndex >= list.size()) {
      list.add(sdOrthogonal);
    }
 else {
      for (int i=sdIndex; i < list.size(); i++) {
        al.add(list.get(i));
      }
      list.set(sdIndex,sdOrthogonal);
      for (int i=1; i < al.size(); i++) {
        list.set(i + sdIndex,al.get(i - 1));
        ((OrthogonalSampleData)list.get(i + sdIndex)).setSeriesDefinitionIndex(i + sdIndex);
      }
      list.add(al.get(al.size() - 1));
      ((OrthogonalSampleData)list.get(list.size() - 1)).setSeriesDefinitionIndex(list.size() - 1);
    }
    ChartAdapter.ignoreNotifications(isNotificaionIgnored);
  }
 else {
    sdTmp.getSeries().add(BarSeriesImpl.create());
    OrthogonalSampleData sampleData=DataFactory.eINSTANCE.createOrthogonalSampleData();
    sampleData.setDataSetRepresentation(ChartUIUtil.getNewSampleData(AxisType.LINEAR_LITERAL,0));
    sampleData.setSeriesDefinitionIndex(0);
    getChart().getSampleData().getOrthogonalSampleData().add(getFirstIndexOfSameAxis(),sampleData);
  }
  seriesDefns.add(sdTmp);
}