Program: 65914
Project: 65914
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(fsTypeLiteral)) {
      currentChart.setType(fsTypeLiteral);
      currentChart.setSubType(sNewSubType);
      Text title=currentChart.getTitle().getLabel().getCaption();
      if (title != null && 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 (!ChartPreviewPainterBase.isLivePreviewActive() && axes.get(i).isSetType() && !isNumbericAxis(axes.get(i))) {
          axes.get(i).setType(AxisType.LINEAR_LITERAL);
        }
        axes.get(i).setPercent(sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL));
        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 (!ChartPreviewPainterBase.isLivePreviewActive() && axes.get(i).isSetType() && !isNumbericAxis(axes.get(i))) {
            axes.get(i).setType(AxisType.LINEAR_LITERAL);
          }
          boolean isStacked=(sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL));
          series.setStacked(isStacked);
          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 {
      EList<Axis> axes=((ChartWithAxes)currentChart).getAxes().get(0).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (!currentChart.getSubType().equals(sNewSubType)) {
          if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
            if (!ChartPreviewPainterBase.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 (!ChartPreviewPainterBase.isLivePreviewActive() && axes.get(i).isSetType() && !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);
          }
        }
      }
      if (!currentChart.getSubType().equals(sNewSubType)) {
        currentChart.setSubType(sNewSubType);
      }
    }
  }
 else {
    currentChart=ChartWithAxesImpl.createDefault();
    copyChartProperties(helperModel,currentChart);
    currentChart.setType(fsTypeLiteral);
    currentChart.setSubType(sNewSubType);
    ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",newOrientation,newOrientation == null);
    ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",ChartUIUtil.getDimensionType(sNewDimension),sNewDimension == null);
{
      (((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().clear();
      (((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().add(((ChartWithoutAxes)helperModel).getSeriesDefinitions().get(0));
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().clear();
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().addAll(((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeriesDefinitions());
      Series series=((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getDesignTimeSeries();
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().clear();
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().add(series);
      EList<SeriesDefinition> seriesdefinitions=((((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions();
      for (int j=0; j < seriesdefinitions.size(); j++) {
        series=(seriesdefinitions.get(j)).getDesignTimeSeries();
        series=getConvertedSeries(series,j);
        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);
      }
    }
    Text title=currentChart.getTitle().getLabel().getCaption();
    if (title != null && title.getValue() != null && (title.getValue().trim().length() == 0 || title.getValue().trim().equals(oldType.getDefaultTitle().trim()))) {
      title.setValue(getDefaultTitle());
    }
  }
  ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",newOrientation,newOrientation == null);
  ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",ChartUIUtil.getDimensionType(sNewDimension),sNewDimension == null);
  if (sNewDimension != null && sNewDimension.equals(THREE_DIMENSION_TYPE) && ChartUIUtil.getDimensionType(sNewDimension) != oldDimension) {
    ((ChartWithAxes)currentChart).setRotation(Rotation3DImpl.createDefault(new Angle3D[]{Angle3DImpl.createDefault(-20,45,0)}));
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().clear();
    Axis zAxisAncillary=AxisImpl.createDefault(Axis.ANCILLARY_BASE);
    zAxisAncillary.getOrigin().setValue(NumberDataElementImpl.create(0));
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().add(zAxisAncillary);
    SeriesDefinition sdZ=SeriesDefinitionImpl.createDefault();
    sdZ.getSeries().add(SeriesImpl.createDefault());
    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();
      if (series instanceof BarSeries) {
        ((BarSeries)series).setRiser(foRiserType);
      }
      series.setStacked(false);
      if ((series instanceof BarSeries) && series.isSetLabelPosition() && (series.getLabelPosition() != Position.OUTSIDE_LITERAL)) {
        series.setLabelPosition(Position.OUTSIDE_LITERAL);
      }
    }
  }
  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(fsTypeLiteral)) {
      currentChart.setType(fsTypeLiteral);
      currentChart.setSubType(sNewSubType);
      Text title=currentChart.getTitle().getLabel().getCaption();
      if (title != null && 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 (!ChartPreviewPainterBase.isLivePreviewActive() && axes.get(i).isSetType() && !isNumbericAxis(axes.get(i))) {
          axes.get(i).setType(AxisType.LINEAR_LITERAL);
        }
        axes.get(i).setPercent(sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL));
        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 (!ChartPreviewPainterBase.isLivePreviewActive() && axes.get(i).isSetType() && !isNumbericAxis(axes.get(i))) {
            axes.get(i).setType(AxisType.LINEAR_LITERAL);
          }
          boolean isStacked=(sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL));
          series.setStacked(isStacked);
          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 {
      EList<Axis> axes=((ChartWithAxes)currentChart).getAxes().get(0).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (!currentChart.getSubType().equals(sNewSubType)) {
          if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
            if (!ChartPreviewPainterBase.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 (!ChartPreviewPainterBase.isLivePreviewActive() && axes.get(i).isSetType() && !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);
          }
        }
      }
      if (!currentChart.getSubType().equals(sNewSubType)) {
        currentChart.setSubType(sNewSubType);
      }
    }
  }
 else {
    currentChart=ChartWithAxesImpl.createDefault();
    copyChartProperties(helperModel,currentChart);
    currentChart.setType(fsTypeLiteral);
    currentChart.setSubType(sNewSubType);
    ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",newOrientation,newOrientation == null);
    ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",ChartUIUtil.getDimensionType(sNewDimension),sNewDimension == null);
    try {
      ChartElementUtil.setDefaultValue(((ChartWithAxes)currentChart).getAxes().get(0),"String_Node_Str",true);
    }
 catch (    ChartException e) {
    }
{
      (((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().clear();
      (((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().add(((ChartWithoutAxes)helperModel).getSeriesDefinitions().get(0));
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().clear();
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().addAll(((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeriesDefinitions());
      Series series=((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getDesignTimeSeries();
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().clear();
      ((((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().add(series);
      EList<SeriesDefinition> seriesdefinitions=((((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions();
      for (int j=0; j < seriesdefinitions.size(); j++) {
        series=(seriesdefinitions.get(j)).getDesignTimeSeries();
        series=getConvertedSeries(series,j);
        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);
      }
    }
    Text title=currentChart.getTitle().getLabel().getCaption();
    if (title != null && title.getValue() != null && (title.getValue().trim().length() == 0 || title.getValue().trim().equals(oldType.getDefaultTitle().trim()))) {
      title.setValue(getDefaultTitle());
    }
  }
  ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",newOrientation,newOrientation == null);
  ChartElementUtil.setEObjectAttribute(currentChart,"String_Node_Str",ChartUIUtil.getDimensionType(sNewDimension),sNewDimension == null);
  if (sNewDimension != null && sNewDimension.equals(THREE_DIMENSION_TYPE) && ChartUIUtil.getDimensionType(sNewDimension) != oldDimension) {
    ((ChartWithAxes)currentChart).setRotation(Rotation3DImpl.createDefault(new Angle3D[]{Angle3DImpl.createDefault(-20,45,0)}));
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().clear();
    Axis zAxisAncillary=AxisImpl.createDefault(Axis.ANCILLARY_BASE);
    zAxisAncillary.getOrigin().setValue(NumberDataElementImpl.create(0));
    ((ChartWithAxes)currentChart).getPrimaryBaseAxes()[0].getAncillaryAxes().add(zAxisAncillary);
    SeriesDefinition sdZ=SeriesDefinitionImpl.createDefault();
    sdZ.getSeries().add(SeriesImpl.createDefault());
    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();
      if (series instanceof BarSeries) {
        ((BarSeries)series).setRiser(foRiserType);
      }
      series.setStacked(false);
      if ((series instanceof BarSeries) && series.isSetLabelPosition() && (series.getLabelPosition() != Position.OUTSIDE_LITERAL)) {
        series.setLabelPosition(Position.OUTSIDE_LITERAL);
      }
    }
  }
  ChartUIUtil.restoreLabelPositionFromCache(currentChart);
  return currentChart;
}