Program: 75469
Project: 75469
Buggy source:
private Chart getConvertedChart(Chart currentChart,String sNewSubType,Orientation newOrientation,String sNewDimension){
  Chart helperModel=(Chart)EcoreUtil.copy(currentChart);
  ChartDimension oldDimension=currentChart.getDimension();
  ChartCacheManager.getInstance().cacheSeries(ChartUIUtil.getAllOrthogonalSeriesDefinitions(helperModel));
  if ((currentChart instanceof ChartWithAxes)) {
    if (!currentChart.getType().equals(TYPE_LITERAL)) {
      currentChart.setType(TYPE_LITERAL);
      currentChart.setSubType(sNewSubType);
      currentChart.getTitle().getLabel().getCaption().setValue(CHART_TITLE);
      ArrayList axisTypes=new ArrayList();
      EList axes=((Axis)((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((Axis)axes.get(i))) {
            ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
          }
          ((Axis)axes.get(i)).setPercent(true);
        }
 else {
          ((Axis)axes.get(i)).setPercent(false);
        }
        EList seriesdefinitions=((Axis)axes.get(i)).getSeriesDefinitions();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=((SeriesDefinition)seriesdefinitions.get(j)).getDesignTimeSeries();
          series=getConvertedSeries(series,seriesIndex++);
          if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
            if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
              ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
            }
            series.setStacked(true);
          }
 else {
            series.setStacked(false);
          }
          ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().clear();
          ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().add(series);
          axisTypes.add(((Axis)axes.get(i)).getType());
        }
      }
      currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData(),((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getType(),axisTypes));
    }
 else {
      EList axes=((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes();
      for (int i=0; i < axes.size(); i++) {
        if (!currentChart.getSubType().equals(sNewSubType)) {
          if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
            if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
              ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
            }
            ((Axis)axes.get(i)).setPercent(true);
          }
 else {
            ((Axis)axes.get(i)).setPercent(false);
          }
        }
        EList seriesdefinitions=((Axis)axes.get(i)).getSeriesDefinitions();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=((SeriesDefinition)seriesdefinitions.get(j)).getDesignTimeSeries();
          ((BarSeries)series).setRiser(RiserType.RECTANGLE_LITERAL);
          if (!currentChart.getSubType().equals(sNewSubType)) {
            if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
              if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
                ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
              }
              series.setStacked(true);
            }
 else {
              series.setStacked(false);
            }
          }
        }
      }
      if (!currentChart.getSubType().equals(sNewSubType)) {
        currentChart.setSubType(sNewSubType);
      }
    }
  }
 else {
    currentChart=ChartWithAxesImpl.create();
    currentChart.setType(TYPE_LITERAL);
    currentChart.setSubType(sNewSubType);
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
    currentChart.setDimension(ChartUIUtil.getDimensionType(sNewDimension));
    ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).setOrientation(Orientation.HORIZONTAL_LITERAL);
    ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).setCategoryAxis(true);
    ((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).setOrientation(Orientation.VERTICAL_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)) {
      ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().clear();
      ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().add(((ChartWithoutAxes)helperModel).getSeriesDefinitions().get(0));
      ((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().clear();
      ((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().addAll(((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeriesDefinitions());
      Series series=((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getDesignTimeSeries();
      ((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().clear();
      ((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().add(series);
      EList seriesdefinitions=((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions();
      for (int j=0; j < seriesdefinitions.size(); j++) {
        series=((SeriesDefinition)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);
        }
        ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().clear();
        ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().add(series);
      }
    }
 else {
      return null;
    }
    currentChart.getLegend().setItemType(LegendItemType.SERIES_LITERAL);
    currentChart.getTitle().getLabel().getCaption().setValue(CHART_TITLE);
  }
  if (currentChart instanceof ChartWithAxes && !((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 seriesdefinitions=ChartUIUtil.getOrthogonalSeriesDefinitions(currentChart,0);
    for (int j=0; j < seriesdefinitions.size(); j++) {
      Series series=((SeriesDefinition)seriesdefinitions.get(j)).getDesignTimeSeries();
      ((BarSeries)series).setRiser(RiserType.RECTANGLE_LITERAL);
      series.setStacked(false);
      if ((series instanceof BarSeries) && (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=(Chart)EcoreUtil.copy(currentChart);
  ChartDimension oldDimension=currentChart.getDimension();
  ChartCacheManager.getInstance().cacheSeries(ChartUIUtil.getAllOrthogonalSeriesDefinitions(helperModel));
  if ((currentChart instanceof ChartWithAxes)) {
    if (!currentChart.getType().equals(TYPE_LITERAL)) {
      currentChart.setType(TYPE_LITERAL);
      currentChart.setSubType(sNewSubType);
      currentChart.getTitle().getLabel().getCaption().setValue(CHART_TITLE);
      ArrayList axisTypes=new ArrayList();
      EList axes=((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes();
      for (int i=0, seriesIndex=0; i < axes.size(); i++) {
        if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
          ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
        }
        ((Axis)axes.get(i)).setPercent(sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL));
        EList seriesdefinitions=((Axis)axes.get(i)).getSeriesDefinitions();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=((SeriesDefinition)seriesdefinitions.get(j)).getDesignTimeSeries();
          series=getConvertedSeries(series,seriesIndex++);
          if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
            ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
          }
          boolean isStacked=(sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL));
          series.setStacked(isStacked);
          ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().clear();
          ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().add(series);
          axisTypes.add(((Axis)axes.get(i)).getType());
        }
      }
      currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData(),((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getType(),axisTypes));
    }
 else {
      EList axes=((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes();
      for (int i=0; i < axes.size(); i++) {
        if (!currentChart.getSubType().equals(sNewSubType)) {
          if (sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL)) {
            if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
              ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
            }
            ((Axis)axes.get(i)).setPercent(true);
          }
 else {
            ((Axis)axes.get(i)).setPercent(false);
          }
        }
        EList seriesdefinitions=((Axis)axes.get(i)).getSeriesDefinitions();
        for (int j=0; j < seriesdefinitions.size(); j++) {
          Series series=((SeriesDefinition)seriesdefinitions.get(j)).getDesignTimeSeries();
          ((BarSeries)series).setRiser(RiserType.RECTANGLE_LITERAL);
          if (!currentChart.getSubType().equals(sNewSubType)) {
            if ((sNewSubType.equalsIgnoreCase(STACKED_SUBTYPE_LITERAL) || sNewSubType.equalsIgnoreCase(PERCENTSTACKED_SUBTYPE_LITERAL))) {
              if (!ChartPreviewPainter.isLivePreviewActive() && !isNumbericAxis((Axis)axes.get(i))) {
                ((Axis)axes.get(i)).setType(AxisType.LINEAR_LITERAL);
              }
              series.setStacked(true);
            }
 else {
              series.setStacked(false);
            }
          }
        }
      }
      if (!currentChart.getSubType().equals(sNewSubType)) {
        currentChart.setSubType(sNewSubType);
      }
    }
  }
 else {
    currentChart=ChartWithAxesImpl.create();
    currentChart.setType(TYPE_LITERAL);
    currentChart.setSubType(sNewSubType);
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
    currentChart.setDimension(ChartUIUtil.getDimensionType(sNewDimension));
    ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).setOrientation(Orientation.HORIZONTAL_LITERAL);
    ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).setCategoryAxis(true);
    ((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).setOrientation(Orientation.VERTICAL_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)) {
      ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().clear();
      ((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().add(((ChartWithoutAxes)helperModel).getSeriesDefinitions().get(0));
      ((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().clear();
      ((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions().addAll(((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeriesDefinitions());
      Series series=((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getDesignTimeSeries();
      ((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().clear();
      ((SeriesDefinition)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getSeriesDefinitions().get(0)).getSeries().add(series);
      EList seriesdefinitions=((Axis)((Axis)((ChartWithAxes)currentChart).getAxes().get(0)).getAssociatedAxes().get(0)).getSeriesDefinitions();
      for (int j=0; j < seriesdefinitions.size(); j++) {
        series=((SeriesDefinition)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);
        }
        ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().clear();
        ((SeriesDefinition)seriesdefinitions.get(j)).getSeries().add(series);
      }
    }
 else {
      return null;
    }
    currentChart.getLegend().setItemType(LegendItemType.SERIES_LITERAL);
    currentChart.getTitle().getLabel().getCaption().setValue(CHART_TITLE);
  }
  if (currentChart instanceof ChartWithAxes && !((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 seriesdefinitions=ChartUIUtil.getOrthogonalSeriesDefinitions(currentChart,0);
    for (int j=0; j < seriesdefinitions.size(); j++) {
      Series series=((SeriesDefinition)seriesdefinitions.get(j)).getDesignTimeSeries();
      ((BarSeries)series).setRiser(RiserType.RECTANGLE_LITERAL);
      series.setStacked(false);
      if ((series instanceof BarSeries) && (series.getLabelPosition() != Position.OUTSIDE_LITERAL)) {
        series.setLabelPosition(Position.OUTSIDE_LITERAL);
      }
    }
  }
  ChartUIUtil.restoreLabelPositionFromCache(currentChart);
  return currentChart;
}