Program: 26331
Project: 26331
Buggy source:
/** 
 * Prepares the legend and calculates all needed forms, labels and colors.
 * @param data
 */
public void computeLegend(ChartData<?> data){
  if (!mLegend.isLegendCustom()) {
    List<String> labels=new ArrayList<String>();
    List<Integer> colors=new ArrayList<Integer>();
    for (int i=0; i < data.getDataSetCount(); i++) {
      IDataSet dataSet=data.getDataSetByIndex(i);
      List<Integer> clrs=dataSet.getColors();
      int entryCount=dataSet.getEntryCount();
      if (dataSet instanceof IBarDataSet && ((IBarDataSet)dataSet).isStacked()) {
        IBarDataSet bds=(IBarDataSet)dataSet;
        String[] sLabels=bds.getStackLabels();
        for (int j=0; j < clrs.size() && j < bds.getStackSize(); j++) {
          labels.add(sLabels[j % sLabels.length]);
          colors.add(clrs.get(j));
        }
        if (bds.getLabel() != null) {
          colors.add(ColorTemplate.COLOR_SKIP);
          labels.add(bds.getLabel());
        }
      }
 else       if (dataSet instanceof IPieDataSet) {
        List<String> xVals=data.getXVals();
        IPieDataSet pds=(IPieDataSet)dataSet;
        for (int j=0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) {
          labels.add(xVals.get(j));
          colors.add(clrs.get(j));
        }
        if (pds.getLabel() != null) {
          colors.add(ColorTemplate.COLOR_SKIP);
          labels.add(pds.getLabel());
        }
      }
 else {
        for (int j=0; j < clrs.size() && j < entryCount; j++) {
          if (j < clrs.size() - 1 && j < entryCount - 1) {
            labels.add(null);
          }
 else {
            String label=data.getDataSetByIndex(i).getLabel();
            labels.add(label);
          }
          colors.add(clrs.get(j));
        }
      }
    }
    if (mLegend.getExtraColors() != null && mLegend.getExtraLabels() != null) {
      for (      int color : mLegend.getExtraColors())       colors.add(color);
      Collections.addAll(labels,mLegend.getExtraLabels());
    }
    mLegend.setComputedColors(colors);
    mLegend.setComputedLabels(labels);
  }
  Typeface tf=mLegend.getTypeface();
  if (tf != null)   mLegendLabelPaint.setTypeface(tf);
  mLegendLabelPaint.setTextSize(mLegend.getTextSize());
  mLegendLabelPaint.setColor(mLegend.getTextColor());
  mLegend.calculateDimensions(mLegendLabelPaint,mViewPortHandler);
}

Fixed version (ground truth):
/** 
 * Prepares the legend and calculates all needed forms, labels and colors.
 * @param data
 */
public void computeLegend(ChartData<?> data){
  if (!mLegend.isLegendCustom()) {
    List<String> labels=new ArrayList<String>();
    List<Integer> colors=new ArrayList<Integer>();
    for (int i=0; i < data.getDataSetCount(); i++) {
      IDataSet dataSet=data.getDataSetByIndex(i);
      List<Integer> clrs=dataSet.getColors();
      int entryCount=dataSet.getEntryCount();
      if (dataSet instanceof IBarDataSet && ((IBarDataSet)dataSet).isStacked()) {
        IBarDataSet bds=(IBarDataSet)dataSet;
        String[] sLabels=bds.getStackLabels();
        for (int j=0; j < clrs.size() && j < bds.getStackSize(); j++) {
          labels.add(sLabels[j % sLabels.length]);
          colors.add(clrs.get(j));
        }
        if (bds.getLabel() != null) {
          colors.add(ColorTemplate.COLOR_SKIP);
          labels.add(bds.getLabel());
        }
      }
 else       if (dataSet instanceof IPieDataSet) {
        List<String> xVals=data.getXVals();
        IPieDataSet pds=(IPieDataSet)dataSet;
        for (int j=0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) {
          labels.add(xVals.get(j));
          colors.add(clrs.get(j));
        }
        if (pds.getLabel() != null) {
          colors.add(ColorTemplate.COLOR_SKIP);
          labels.add(pds.getLabel());
        }
      }
 else       if (dataSet instanceof ICandleDataSet && ((ICandleDataSet)dataSet).getDecreasingColor() != ColorTemplate.COLOR_NONE) {
        colors.add(((ICandleDataSet)dataSet).getDecreasingColor());
        colors.add(((ICandleDataSet)dataSet).getIncreasingColor());
        labels.add(null);
        labels.add(dataSet.getLabel());
      }
 else {
        for (int j=0; j < clrs.size() && j < entryCount; j++) {
          if (j < clrs.size() - 1 && j < entryCount - 1) {
            labels.add(null);
          }
 else {
            String label=data.getDataSetByIndex(i).getLabel();
            labels.add(label);
          }
          colors.add(clrs.get(j));
        }
      }
    }
    if (mLegend.getExtraColors() != null && mLegend.getExtraLabels() != null) {
      for (      int color : mLegend.getExtraColors())       colors.add(color);
      Collections.addAll(labels,mLegend.getExtraLabels());
    }
    mLegend.setComputedColors(colors);
    mLegend.setComputedLabels(labels);
  }
  Typeface tf=mLegend.getTypeface();
  if (tf != null)   mLegendLabelPaint.setTypeface(tf);
  mLegendLabelPaint.setTextSize(mLegend.getTextSize());
  mLegendLabelPaint.setColor(mLegend.getTextColor());
  mLegend.calculateDimensions(mLegendLabelPaint,mViewPortHandler);
}