Program: 69437
Project: 69437
Buggy source:
private Chart getConvertedChart(Chart currentChart,String sNewSubType,Orientation newOrientation,String sNewDimension){
  Chart helperModel=currentChart.copyInstance();
  ChartCacheManager.getInstance().cacheSeries(ChartUIUtil.getAllOrthogonalSeriesDefinitions(helperModel));
  if ((currentChart instanceof ChartWithAxes)) {
    Axis xAxis=((ChartWithAxes)currentChart).getAxes().get(0);
    if (currentChart.getType().equals(TYPE_LITERAL)) {
      if (!currentChart.getSubType().equals(sNewSubType)) {
        currentChart.setSubType(sNewSubType);
        for (        Axis yAxis : xAxis.getAssociatedAxes()) {
          yAxis.setPercent(false);
          for (          SeriesDefinition ysd : yAxis.getSeriesDefinitions()) {
            Series series=ysd.getDesignTimeSeries();
            series.setStacked(false);
            if (series instanceof StockSeries) {
              ((StockSeries)series).setShowAsBarStick(BAR_STICK_SUBTYPE_LITERAL.equals(currentChart.getSubType()));
            }
          }
        }
      }
    }
 else {
      if (!currentChart.getType().equals(TYPE_LITERAL)) {
        currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData(),false));
      }
      currentChart.setType(TYPE_LITERAL);
      currentChart.getTitle().getLabel().getCaption().setValue(CHART_TITLE);
      xAxis.setCategoryAxis(true);
      currentChart.setSubType(sNewSubType);
      int seriesIndex=0;
      for (      Axis yAxis : xAxis.getAssociatedAxes()) {
        if (!ChartPreviewPainter.isLivePreviewActive()) {
          yAxis.setType(AxisType.LINEAR_LITERAL);
        }
        yAxis.setPercent(false);
        for (        SeriesDefinition ysd : yAxis.getSeriesDefinitions()) {
          Series series=ysd.getDesignTimeSeries();
          series=getConvertedSeries(series,seriesIndex);
          series.setStacked(false);
          ysd.getSeries().clear();
          ysd.getSeries().add(series);
          seriesIndex++;
        }
      }
    }
  }
 else {
    currentChart=ChartWithAxesImpl.create();
    currentChart.setType(TYPE_LITERAL);
    currentChart.setSubType(sNewSubType);
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
    currentChart.setDimension(getDimensionFor(sNewDimension));
    Axis xAxis=((ChartWithAxes)currentChart).getAxes().get(0);
    xAxis.setOrientation(Orientation.HORIZONTAL_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(getConvertedSampleData(helperModel.getSampleData(),true));
    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());
      SeriesDefinition bsd=xAxis.getSeriesDefinitions().get(0);
      Series series=bsd.getDesignTimeSeries();
      bsd.getSeries().clear();
      bsd.getSeries().add(series);
      int j=0;
      for (      SeriesDefinition vsd : yAxis.getSeriesDefinitions()) {
        series=vsd.getDesignTimeSeries();
        series=getConvertedSeries(series,j++);
        series.getLabel().setVisible(false);
        series.setStacked(false);
        vsd.getSeries().clear();
        vsd.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(getDimensionFor(sNewDimension))) {
    currentChart.setDimension(getDimensionFor(sNewDimension));
  }
  ChartUIUtil.restoreLabelPositionFromCache(currentChart);
  ChartUIUtil.updateDefaultAggregations(currentChart);
  return currentChart;
}

Fixed version (ground truth):
private Chart getConvertedChart(Chart currentChart,String sNewSubType,Orientation newOrientation,String sNewDimension){
  Chart helperModel=currentChart.copyInstance();
  ChartCacheManager.getInstance().cacheSeries(ChartUIUtil.getAllOrthogonalSeriesDefinitions(helperModel));
  if ((currentChart instanceof ChartWithAxes)) {
    Axis xAxis=((ChartWithAxes)currentChart).getAxes().get(0);
    if (currentChart.getType().equals(TYPE_LITERAL)) {
      if (!currentChart.getSubType().equals(sNewSubType)) {
        currentChart.setSubType(sNewSubType);
        for (        Axis yAxis : xAxis.getAssociatedAxes()) {
          yAxis.setPercent(false);
          for (          SeriesDefinition ysd : yAxis.getSeriesDefinitions()) {
            Series series=ysd.getDesignTimeSeries();
            series.setStacked(false);
            if (series instanceof StockSeries) {
              ((StockSeries)series).setShowAsBarStick(BAR_STICK_SUBTYPE_LITERAL.equals(currentChart.getSubType()));
            }
          }
        }
      }
    }
 else {
      if (!currentChart.getType().equals(TYPE_LITERAL)) {
        currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData(),false));
      }
      currentChart.setType(TYPE_LITERAL);
      currentChart.getTitle().getLabel().getCaption().setValue(CHART_TITLE);
      xAxis.setCategoryAxis(true);
      currentChart.setSubType(sNewSubType);
      int seriesIndex=0;
      for (      Axis yAxis : xAxis.getAssociatedAxes()) {
        if (!ChartPreviewPainter.isLivePreviewActive()) {
          yAxis.setType(AxisType.LINEAR_LITERAL);
        }
        yAxis.setPercent(false);
        for (        SeriesDefinition ysd : yAxis.getSeriesDefinitions()) {
          Series series=ysd.getDesignTimeSeries();
          series=getConvertedSeries(series,seriesIndex);
          series.setStacked(false);
          ysd.getSeries().clear();
          ysd.getSeries().add(series);
          seriesIndex++;
        }
      }
    }
  }
 else {
    currentChart=ChartWithAxesImpl.create();
    currentChart.setType(TYPE_LITERAL);
    currentChart.setSubType(sNewSubType);
    ((ChartWithAxes)currentChart).setOrientation(newOrientation);
    currentChart.setDimension(getDimensionFor(sNewDimension));
    Axis xAxis=((ChartWithAxes)currentChart).getAxes().get(0);
    xAxis.setOrientation(Orientation.HORIZONTAL_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(getConvertedSampleData(helperModel.getSampleData(),true));
    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());
      SeriesDefinition bsd=xAxis.getSeriesDefinitions().get(0);
      Series series=bsd.getDesignTimeSeries();
      bsd.getSeries().clear();
      bsd.getSeries().add(series);
      int j=0;
      for (      SeriesDefinition vsd : yAxis.getSeriesDefinitions()) {
        series=vsd.getDesignTimeSeries();
        series=getConvertedSeries(series,j++);
        series.getLabel().setVisible(false);
        series.setStacked(false);
        vsd.getSeries().clear();
        vsd.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(getDimensionFor(sNewDimension))) {
    currentChart.setDimension(getDimensionFor(sNewDimension));
  }
  ChartUIUtil.restoreLabelPositionFromCache(currentChart);
  SeriesGrouping sg=ChartUtil.getBaseSeriesDefinitions(currentChart).get(0).getGrouping();
  if (sg.getGroupType().getValue() == DataType.DATE_TIME) {
    ChartUIUtil.updateDefaultAggregations(currentChart);
  }
  return currentChart;
}