Program: 68022
Project: 68022
Buggy source:
private Chart getConvertedChart(Chart currentChart,String sNewSubType,Orientation newOrientation,String sNewDimension){
  Chart helperModel=currentChart.copyInstance();
  helperModel.eAdapters().addAll(currentChart.eAdapters());
  ChartDimension oldDimension=currentChart.getDimension();
  ChartCacheManager.getInstance().cacheSeries(ChartUIUtil.getAllOrthogonalSeriesDefinitions(helperModel));
  IChartType oldType=ChartUIUtil.getChartType(currentChart.getType());
  if ((currentChart instanceof ChartWithAxes)) {
    if (currentChart.getType().equals(TYPE_LITERAL)) {
      currentChart.setSubType(sNewSubType);
      EList<Axis> axes=((ChartWithAxes)currentChart).getAxes().get(0).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
          if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis(axes.get(i))) {
            axes.get(i).setType(AxisType.LINEAR_LITERAL);
          }
          axes.get(i).setPercent(true);
        }
 else {
          axes.get(i).setPercent(false);
        }
        EList<SeriesDefinition> seriesdefinitions=axes.get(i).getSeriesDefinitions();
        Series firstSeries=seriesdefinitions.get(0).getDesignTimeSeries();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=seriesdefinitions.get(j).getDesignTimeSeries();
          if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
            if (j != 0) {
              series=getConvertedSeriesAsFirst(series,seriesIndex,firstSeries);
            }
            seriesIndex++;
            if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis(axes.get(i))) {
              axes.get(i).setType(AxisType.LINEAR_LITERAL);
            }
            if (series.canBeStacked()) {
              series.setStacked(true);
            }
            seriesdefinitions.get(j).getSeries().clear();
            seriesdefinitions.get(j).getSeries().add(series);
          }
 else {
            series.setStacked(false);
          }
        }
      }
    }
 else     if (currentChart.getType().equals(BarChart.TYPE_LITERAL) || currentChart.getType().equals(TubeChart.TYPE_LITERAL) || currentChart.getType().equals(ConeChart.TYPE_LITERAL)|| currentChart.getType().equals(PyramidChart.TYPE_LITERAL)|| currentChart.getType().equals(LineChart.TYPE_LITERAL)|| currentChart.getType().equals(StockChart.TYPE_LITERAL)|| currentChart.getType().equals(ScatterChart.TYPE_LITERAL)|| currentChart.getType().equals(BubbleChart.TYPE_LITERAL)|| currentChart.getType().equals(DifferenceChart.TYPE_LITERAL)|| currentChart.getType().equals(GanttChart.TYPE_LITERAL)) {
      currentChart.setType(TYPE_LITERAL);
      currentChart.setSubType(sNewSubType);
      Text title=currentChart.getTitle().getLabel().getCaption();
      if (title.getValue() == null || title.getValue().trim().length() == 0 || title.getValue().trim().equals(oldType.getDefaultTitle().trim())) {
        title.setValue(getDefaultTitle());
      }
      List<AxisType> axisTypes=new ArrayList<AxisType>();
      EList<Axis> axes=((ChartWithAxes)currentChart).getAxes().get(0).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis(axes.get(i))) {
          axes.get(i).setType(AxisType.LINEAR_LITERAL);
        }
        if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
          axes.get(i).setPercent(true);
        }
 else {
          axes.get(i).setPercent(false);
        }
        EList<SeriesDefinition> seriesdefinitions=axes.get(i).getSeriesDefinitions();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=seriesdefinitions.get(j).getDesignTimeSeries();
          series=getConvertedSeries(series,seriesIndex++);
          if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
            series.setStacked(true);
          }
 else {
            series.setStacked(false);
          }
          seriesdefinitions.get(j).getSeries().clear();
          seriesdefinitions.get(j).getSeries().add(series);
          axisTypes.add(axes.get(i).getType());
        }
      }
      currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData(),((ChartWithAxes)currentChart).getAxes().get(0).getType(),axisTypes));
    }
 else {
      return null;
    }
  }
 else {
    currentChart=ChartWithAxesImpl.create();
    currentChart.eAdapters().addAll(helperModel.eAdapters());
    currentChart.setType(TYPE_LITERAL);
    currentChart.setSubType(sNewSubType);
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
    currentChart.setDimension(ChartUIUtil.getDimensionType(sNewDimension));
    Axis xAxis=((ChartWithAxes)currentChart).getAxes().get(0);
    xAxis.setOrientation(Orientation.HORIZONTAL_LITERAL);
    xAxis.setType(AxisType.TEXT_LITERAL);
    xAxis.setCategoryAxis(true);
    Axis yAxis=xAxis.getAssociatedAxes().get(0);
    yAxis.setOrientation(Orientation.VERTICAL_LITERAL);
    yAxis.setType(AxisType.LINEAR_LITERAL);
    currentChart.setBlock(helperModel.getBlock());
    currentChart.setDescription(helperModel.getDescription());
    currentChart.setGridColumnCount(helperModel.getGridColumnCount());
    currentChart.setSampleData(helperModel.getSampleData());
    currentChart.setScript(helperModel.getScript());
    currentChart.setSeriesThickness(helperModel.getSeriesThickness());
    currentChart.setUnits(helperModel.getUnits());
    if (helperModel.getInteractivity() != null) {
      currentChart.getInteractivity().setEnable(helperModel.getInteractivity().isEnable());
      currentChart.getInteractivity().setLegendBehavior(helperModel.getInteractivity().getLegendBehavior());
    }
    if (helperModel.getType().equals(PieChart.TYPE_LITERAL) || helperModel.getType().equals(MeterChart.TYPE_LITERAL)) {
      xAxis.getSeriesDefinitions().clear();
      xAxis.getSeriesDefinitions().add(((ChartWithoutAxes)helperModel).getSeriesDefinitions().get(0));
      yAxis.getSeriesDefinitions().clear();
      yAxis.getSeriesDefinitions().addAll(xAxis.getSeriesDefinitions().get(0).getSeriesDefinitions());
      Series series=xAxis.getSeriesDefinitions().get(0).getDesignTimeSeries();
      xAxis.getSeriesDefinitions().get(0).getSeries().clear();
      xAxis.getSeriesDefinitions().get(0).getSeries().add(series);
      EList<SeriesDefinition> seriesdefinitions=yAxis.getSeriesDefinitions();
      for (int j=0; j < seriesdefinitions.size(); j++) {
        series=seriesdefinitions.get(j).getDesignTimeSeries();
        series=getConvertedSeries(series,j);
        series.getLabel().setVisible(false);
        if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
          series.setStacked(true);
        }
 else {
          series.setStacked(false);
        }
        seriesdefinitions.get(j).getSeries().clear();
        seriesdefinitions.get(j).getSeries().add(series);
      }
    }
 else {
      return null;
    }
    currentChart.getLegend().setItemType(LegendItemType.SERIES_LITERAL);
    Text title=currentChart.getTitle().getLabel().getCaption();
    if (title.getValue() == null || title.getValue().trim().length() == 0 || title.getValue().trim().equals(oldType.getDefaultTitle().trim())) {
      title.setValue(getDefaultTitle());
    }
  }
  if (!((ChartWithAxes)currentChart).getOrientation().equals(newOrientation)) {
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
  }
  if (!currentChart.getDimension().equals(ChartUIUtil.getDimensionType(sNewDimension))) {
    currentChart.setDimension(ChartUIUtil.getDimensionType(sNewDimension));
  }
  if (sNewDimension.equals(THREE_DIMENSION_TYPE) && ChartUIUtil.getDimensionType(sNewDimension) != oldDimension) {
    ((ChartWithAxes)currentChart).setRotation(Rotation3DImpl.create(new Angle3D[]{Angle3DImpl.create(-20,45,0)}));
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().clear();
    Axis zAxisAncillary=AxisImpl.create(Axis.ANCILLARY_BASE);
    zAxisAncillary.setTitlePosition(Position.BELOW_LITERAL);
    zAxisAncillary.getTitle().getCaption().setValue(Messages.getString("String_Node_Str"));
    zAxisAncillary.getTitle().setVisible(true);
    zAxisAncillary.setPrimaryAxis(true);
    zAxisAncillary.setLabelPosition(Position.BELOW_LITERAL);
    zAxisAncillary.setOrientation(Orientation.HORIZONTAL_LITERAL);
    zAxisAncillary.getOrigin().setType(IntersectionType.MIN_LITERAL);
    zAxisAncillary.getOrigin().setValue(NumberDataElementImpl.create(0));
    zAxisAncillary.getTitle().setVisible(false);
    zAxisAncillary.setType(AxisType.TEXT_LITERAL);
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().add(zAxisAncillary);
    SeriesDefinition sdZ=SeriesDefinitionImpl.create();
    sdZ.getSeriesPalette().shift(0);
    sdZ.getSeries().add(SeriesImpl.create());
    zAxisAncillary.getSeriesDefinitions().add(sdZ);
    if (currentChart.getSampleData().getAncillarySampleData().isEmpty()) {
      BaseSampleData sdAncillary=DataFactory.eINSTANCE.createBaseSampleData();
      sdAncillary.setDataSetRepresentation("String_Node_Str");
      currentChart.getSampleData().getAncillarySampleData().add(sdAncillary);
    }
    EList<SeriesDefinition> seriesdefinitions=ChartUIUtil.getOrthogonalSeriesDefinitions(currentChart,0);
    for (int j=0; j < seriesdefinitions.size(); j++) {
      Series series=seriesdefinitions.get(j).getDesignTimeSeries();
      series.setStacked(false);
    }
  }
  ChartUIUtil.restoreLabelPositionFromCache(currentChart);
  return currentChart;
}

Fixed version (ground truth):
private Chart getConvertedChart(Chart currentChart,String sNewSubType,Orientation newOrientation,String sNewDimension){
  Chart helperModel=currentChart.copyInstance();
  helperModel.eAdapters().addAll(currentChart.eAdapters());
  ChartDimension oldDimension=currentChart.getDimension();
  ChartCacheManager.getInstance().cacheSeries(ChartUIUtil.getAllOrthogonalSeriesDefinitions(helperModel));
  IChartType oldType=ChartUIUtil.getChartType(currentChart.getType());
  if ((currentChart instanceof ChartWithAxes)) {
    if (currentChart.getType().equals(TYPE_LITERAL)) {
      currentChart.setSubType(sNewSubType);
      EList<Axis> axes=((ChartWithAxes)currentChart).getAxes().get(0).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
          if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis(axes.get(i))) {
            axes.get(i).setType(AxisType.LINEAR_LITERAL);
          }
          axes.get(i).setPercent(true);
        }
 else {
          axes.get(i).setPercent(false);
        }
        EList<SeriesDefinition> seriesdefinitions=axes.get(i).getSeriesDefinitions();
        Series firstSeries=seriesdefinitions.get(0).getDesignTimeSeries();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=seriesdefinitions.get(j).getDesignTimeSeries();
          if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
            if (j != 0) {
              series=getConvertedSeriesAsFirst(series,seriesIndex,firstSeries);
            }
            seriesIndex++;
            if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis(axes.get(i))) {
              axes.get(i).setType(AxisType.LINEAR_LITERAL);
            }
            if (series.canBeStacked()) {
              series.setStacked(true);
            }
            seriesdefinitions.get(j).getSeries().clear();
            seriesdefinitions.get(j).getSeries().add(series);
          }
 else {
            series.setStacked(false);
          }
        }
      }
    }
 else     if (currentChart.getType().equals(BarChart.TYPE_LITERAL) || currentChart.getType().equals(TubeChart.TYPE_LITERAL) || currentChart.getType().equals(ConeChart.TYPE_LITERAL)|| currentChart.getType().equals(PyramidChart.TYPE_LITERAL)|| currentChart.getType().equals(LineChart.TYPE_LITERAL)|| currentChart.getType().equals(StockChart.TYPE_LITERAL)|| currentChart.getType().equals(ScatterChart.TYPE_LITERAL)|| currentChart.getType().equals(BubbleChart.TYPE_LITERAL)|| currentChart.getType().equals(DifferenceChart.TYPE_LITERAL)|| currentChart.getType().equals(GanttChart.TYPE_LITERAL)) {
      currentChart.setType(TYPE_LITERAL);
      currentChart.setSubType(sNewSubType);
      Text title=currentChart.getTitle().getLabel().getCaption();
      if (title.getValue() == null || title.getValue().trim().length() == 0 || title.getValue().trim().equals(oldType.getDefaultTitle().trim())) {
        title.setValue(getDefaultTitle());
      }
      List<AxisType> axisTypes=new ArrayList<AxisType>();
      EList<Axis> axes=((ChartWithAxes)currentChart).getAxes().get(0).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis(axes.get(i))) {
          axes.get(i).setType(AxisType.LINEAR_LITERAL);
        }
        if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
          axes.get(i).setPercent(true);
        }
 else {
          axes.get(i).setPercent(false);
        }
        EList<SeriesDefinition> seriesdefinitions=axes.get(i).getSeriesDefinitions();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=seriesdefinitions.get(j).getDesignTimeSeries();
          series=getConvertedSeries(series,seriesIndex++);
          if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
            series.setStacked(true);
          }
 else {
            series.setStacked(false);
          }
          seriesdefinitions.get(j).getSeries().clear();
          seriesdefinitions.get(j).getSeries().add(series);
          axisTypes.add(axes.get(i).getType());
        }
      }
      currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData(),((ChartWithAxes)currentChart).getAxes().get(0).getType(),axisTypes));
    }
 else {
      return null;
    }
  }
 else {
    currentChart=ChartWithAxesImpl.create();
    currentChart.eAdapters().addAll(helperModel.eAdapters());
    currentChart.setType(TYPE_LITERAL);
    currentChart.setSubType(sNewSubType);
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
    currentChart.setDimension(ChartUIUtil.getDimensionType(sNewDimension));
    Axis xAxis=((ChartWithAxes)currentChart).getAxes().get(0);
    xAxis.setOrientation(Orientation.HORIZONTAL_LITERAL);
    xAxis.setType(AxisType.TEXT_LITERAL);
    xAxis.setCategoryAxis(true);
    Axis yAxis=xAxis.getAssociatedAxes().get(0);
    yAxis.setOrientation(Orientation.VERTICAL_LITERAL);
    yAxis.setType(AxisType.LINEAR_LITERAL);
    currentChart.setBlock(helperModel.getBlock());
    currentChart.setDescription(helperModel.getDescription());
    currentChart.setGridColumnCount(helperModel.getGridColumnCount());
    currentChart.setSampleData(helperModel.getSampleData());
    currentChart.setScript(helperModel.getScript());
    currentChart.setSeriesThickness(helperModel.getSeriesThickness());
    currentChart.setUnits(helperModel.getUnits());
    if (helperModel.getInteractivity() != null) {
      currentChart.getInteractivity().setEnable(helperModel.getInteractivity().isEnable());
      currentChart.getInteractivity().setLegendBehavior(helperModel.getInteractivity().getLegendBehavior());
    }
{
      xAxis.getSeriesDefinitions().clear();
      xAxis.getSeriesDefinitions().add(((ChartWithoutAxes)helperModel).getSeriesDefinitions().get(0));
      yAxis.getSeriesDefinitions().clear();
      yAxis.getSeriesDefinitions().addAll(xAxis.getSeriesDefinitions().get(0).getSeriesDefinitions());
      Series series=xAxis.getSeriesDefinitions().get(0).getDesignTimeSeries();
      xAxis.getSeriesDefinitions().get(0).getSeries().clear();
      xAxis.getSeriesDefinitions().get(0).getSeries().add(series);
      EList<SeriesDefinition> seriesdefinitions=yAxis.getSeriesDefinitions();
      for (int j=0; j < seriesdefinitions.size(); j++) {
        series=seriesdefinitions.get(j).getDesignTimeSeries();
        series=getConvertedSeries(series,j);
        series.getLabel().setVisible(false);
        if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
          series.setStacked(true);
        }
 else {
          series.setStacked(false);
        }
        seriesdefinitions.get(j).getSeries().clear();
        seriesdefinitions.get(j).getSeries().add(series);
      }
    }
    currentChart.getLegend().setItemType(LegendItemType.SERIES_LITERAL);
    Text title=currentChart.getTitle().getLabel().getCaption();
    if (title.getValue() == null || title.getValue().trim().length() == 0 || title.getValue().trim().equals(oldType.getDefaultTitle().trim())) {
      title.setValue(getDefaultTitle());
    }
  }
  if (!((ChartWithAxes)currentChart).getOrientation().equals(newOrientation)) {
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
  }
  if (!currentChart.getDimension().equals(ChartUIUtil.getDimensionType(sNewDimension))) {
    currentChart.setDimension(ChartUIUtil.getDimensionType(sNewDimension));
  }
  if (sNewDimension.equals(THREE_DIMENSION_TYPE) && ChartUIUtil.getDimensionType(sNewDimension) != oldDimension) {
    ((ChartWithAxes)currentChart).setRotation(Rotation3DImpl.create(new Angle3D[]{Angle3DImpl.create(-20,45,0)}));
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().clear();
    Axis zAxisAncillary=AxisImpl.create(Axis.ANCILLARY_BASE);
    zAxisAncillary.setTitlePosition(Position.BELOW_LITERAL);
    zAxisAncillary.getTitle().getCaption().setValue(Messages.getString("String_Node_Str"));
    zAxisAncillary.getTitle().setVisible(true);
    zAxisAncillary.setPrimaryAxis(true);
    zAxisAncillary.setLabelPosition(Position.BELOW_LITERAL);
    zAxisAncillary.setOrientation(Orientation.HORIZONTAL_LITERAL);
    zAxisAncillary.getOrigin().setType(IntersectionType.MIN_LITERAL);
    zAxisAncillary.getOrigin().setValue(NumberDataElementImpl.create(0));
    zAxisAncillary.getTitle().setVisible(false);
    zAxisAncillary.setType(AxisType.TEXT_LITERAL);
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().add(zAxisAncillary);
    SeriesDefinition sdZ=SeriesDefinitionImpl.create();
    sdZ.getSeriesPalette().shift(0);
    sdZ.getSeries().add(SeriesImpl.create());
    zAxisAncillary.getSeriesDefinitions().add(sdZ);
    if (currentChart.getSampleData().getAncillarySampleData().isEmpty()) {
      BaseSampleData sdAncillary=DataFactory.eINSTANCE.createBaseSampleData();
      sdAncillary.setDataSetRepresentation("String_Node_Str");
      currentChart.getSampleData().getAncillarySampleData().add(sdAncillary);
    }
    EList<SeriesDefinition> seriesdefinitions=ChartUIUtil.getOrthogonalSeriesDefinitions(currentChart,0);
    for (int j=0; j < seriesdefinitions.size(); j++) {
      Series series=seriesdefinitions.get(j).getDesignTimeSeries();
      series.setStacked(false);
    }
  }
  ChartUIUtil.restoreLabelPositionFromCache(currentChart);
  return currentChart;
}