nus-yam/ex-repair huggingface dataset:
Program: 26424
Project: 26424
Buggy source:
protected void drawWeb(Canvas c){
  float sliceangle=mChart.getSliceAngle();
  float factor=mChart.getFactor();
  float rotationangle=mChart.getRotationAngle();
  PointF center=mChart.getCenterOffsets();
  mWebPaint.setStrokeWidth(mChart.getWebLineWidth());
  mWebPaint.setColor(mChart.getWebColor());
  mWebPaint.setAlpha(mChart.getWebAlpha());
  for (int i=0; i < mChart.getData().getXValCount(); i+=mChart.getSkipWebLineCount()) {
    PointF p=Utils.getPosition(center,mChart.getYRange() * factor,sliceangle * i + rotationangle);
    c.drawLine(center.x,center.y,p.x,p.y,mWebPaint);
  }
  mWebPaint.setStrokeWidth(mChart.getWebLineWidthInner());
  mWebPaint.setColor(mChart.getWebColorInner());
  mWebPaint.setAlpha(mChart.getWebAlpha());
  int labelCount=mChart.getYAxis().mEntryCount;
  for (int j=0; j < labelCount; j++) {
    for (int i=0; i < mChart.getData().getXValCount(); i++) {
      float r=(mChart.getYAxis().mEntries[j] - mChart.getYChartMin()) * factor;
      PointF p1=Utils.getPosition(center,r,sliceangle * i + rotationangle);
      PointF p2=Utils.getPosition(center,r,sliceangle * (i + 1) + rotationangle);
      c.drawLine(p1.x,p1.y,p2.x,p2.y,mWebPaint);
    }
  }
}

Fixed version (ground truth):
protected void drawWeb(Canvas c){
  float sliceangle=mChart.getSliceAngle();
  float factor=mChart.getFactor();
  float rotationangle=mChart.getRotationAngle();
  PointF center=mChart.getCenterOffsets();
  mWebPaint.setStrokeWidth(mChart.getWebLineWidth());
  mWebPaint.setColor(mChart.getWebColor());
  mWebPaint.setAlpha(mChart.getWebAlpha());
  final int xIncrements=1 + mChart.getSkipWebLineCount();
  for (int i=0; i < mChart.getData().getXValCount(); i+=xIncrements) {
    PointF p=Utils.getPosition(center,mChart.getYRange() * factor,sliceangle * i + rotationangle);
    c.drawLine(center.x,center.y,p.x,p.y,mWebPaint);
  }
  mWebPaint.setStrokeWidth(mChart.getWebLineWidthInner());
  mWebPaint.setColor(mChart.getWebColorInner());
  mWebPaint.setAlpha(mChart.getWebAlpha());
  int labelCount=mChart.getYAxis().mEntryCount;
  for (int j=0; j < labelCount; j++) {
    for (int i=0; i < mChart.getData().getXValCount(); i++) {
      float r=(mChart.getYAxis().mEntries[j] - mChart.getYChartMin()) * factor;
      PointF p1=Utils.getPosition(center,r,sliceangle * i + rotationangle);
      PointF p2=Utils.getPosition(center,r,sliceangle * (i + 1) + rotationangle);
      c.drawLine(p1.x,p1.y,p2.x,p2.y,mWebPaint);
    }
  }
}
Program: 26426
Project: 26426
Buggy source:
/** 
 * Transform a rectangle with all matrices with potential animation phases.
 * @param r
 * @param phaseY
 */
public void rectValueToPixelHorizontal(RectF r,float phaseY){
  if (r.left > 0)   r.left*=phaseY;
 else   r.right*=phaseY;
  mMatrixValueToPx.mapRect(r);
  mViewPortHandler.getMatrixTouch().mapRect(r);
  mMatrixOffset.mapRect(r);
}

Fixed version (ground truth):
/** 
 * Transform a rectangle with all matrices with potential animation phases.
 * @param r
 * @param phaseY
 */
public void rectValueToPixelHorizontal(RectF r,float phaseY){
  r.left*=phaseY;
  r.right*=phaseY;
  mMatrixValueToPx.mapRect(r);
  mViewPortHandler.getMatrixTouch().mapRect(r);
  mMatrixOffset.mapRect(r);
}
Program: 26427
Project: 26427
Buggy source:
/** 
 * Transform a rectangle with all matrices with potential animation phases.
 * @param r
 * @param phaseY
 */
public void rectValueToPixel(RectF r,float phaseY){
  if (r.top > 0)   r.top*=phaseY;
 else   r.bottom*=phaseY;
  mMatrixValueToPx.mapRect(r);
  mViewPortHandler.getMatrixTouch().mapRect(r);
  mMatrixOffset.mapRect(r);
}

Fixed version (ground truth):
/** 
 * Transform a rectangle with all matrices with potential animation phases.
 * @param r
 * @param phaseY
 */
public void rectValueToPixel(RectF r,float phaseY){
  r.top*=phaseY;
  r.bottom*=phaseY;
  mMatrixValueToPx.mapRect(r);
  mViewPortHandler.getMatrixTouch().mapRect(r);
  mMatrixOffset.mapRect(r);
}
Program: 26428
Project: 26428
Buggy source:
@Override protected float[] getMarkerPosition(Entry e,Highlight highlight){
  int dataSetIndex=highlight.getDataSetIndex();
  float xPos=e.getXIndex();
  float yPos=e.getVal();
  if (this instanceof BarChart) {
    BarData bd=(BarData)mData;
    float space=bd.getGroupSpace();
    int setCount=mData.getDataSetCount();
    int i=e.getXIndex();
    if (this instanceof HorizontalBarChart) {
      float y=i + i * (setCount - 1) + dataSetIndex + space * i + space / 2f;
      yPos=y;
      BarEntry entry=(BarEntry)e;
      if (entry.getVals() != null) {
        xPos=highlight.getRange().to;
      }
 else {
        xPos=e.getVal();
      }
    }
 else {
      float x=i + i * (setCount - 1) + dataSetIndex + space * i + space / 2f;
      xPos=x;
      BarEntry entry=(BarEntry)e;
      if (entry.getVals() != null) {
        yPos=highlight.getRange().to;
      }
 else {
        yPos=e.getVal();
      }
    }
  }
  float[] pts=new float[]{xPos,yPos * mAnimator.getPhaseY()};
  getTransformer(mData.getDataSetByIndex(dataSetIndex).getAxisDependency()).pointValuesToPixel(pts);
  return pts;
}

Fixed version (ground truth):
@Override protected float[] getMarkerPosition(Entry e,Highlight highlight){
  int dataSetIndex=highlight.getDataSetIndex();
  float xPos=e.getXIndex();
  float yPos=e.getVal();
  if (this instanceof BarChart) {
    BarData bd=(BarData)mData;
    float space=bd.getGroupSpace();
    int setCount=mData.getDataSetCount();
    int i=e.getXIndex();
    if (this instanceof HorizontalBarChart) {
      float y=i + i * (setCount - 1) + dataSetIndex + space * i + space / 2f;
      yPos=y;
      BarEntry entry=(BarEntry)e;
      if (entry.getVals() != null) {
        xPos=highlight.getRange().to;
      }
 else {
        xPos=e.getVal();
      }
      xPos*=mAnimator.getPhaseY();
    }
 else {
      float x=i + i * (setCount - 1) + dataSetIndex + space * i + space / 2f;
      xPos=x;
      BarEntry entry=(BarEntry)e;
      if (entry.getVals() != null) {
        yPos=highlight.getRange().to;
      }
 else {
        yPos=e.getVal();
      }
      yPos*=mAnimator.getPhaseY();
    }
  }
 else {
    yPos*=mAnimator.getPhaseY();
  }
  float[] pts=new float[]{xPos,yPos};
  getTransformer(mData.getDataSetByIndex(dataSetIndex).getAxisDependency()).pointValuesToPixel(pts);
  return pts;
}
Program: 26429
Project: 26429
Buggy source:
@Override protected void calcMinMax(){
  super.calcMinMax();
  if (getBarData() != null || getCandleData() != null || getBubbleData() != null) {
    mXChartMin=-0.5f;
    mXChartMax=mData.getXVals().size() - 0.5f;
    if (getBubbleData() != null) {
      for (      BubbleDataSet set : getBubbleData().getDataSets()) {
        final float xmin=set.getXMin();
        final float xmax=set.getXMax();
        if (xmin < mXChartMin)         mXChartMin=xmin;
        if (xmax > mXChartMax)         mXChartMax=xmax;
      }
    }
  }
 else {
    mXChartMin=0f;
    mXChartMax=mData.getXValCount() - 1;
  }
  mDeltaX=Math.abs(mXChartMax - mXChartMin);
}

Fixed version (ground truth):
@Override protected void calcMinMax(){
  super.calcMinMax();
  if (getBarData() != null || getCandleData() != null || getBubbleData() != null) {
    mXChartMin=-0.5f;
    mXChartMax=mData.getXVals().size() - 0.5f;
    if (getBubbleData() != null) {
      for (      BubbleDataSet set : getBubbleData().getDataSets()) {
        final float xmin=set.getXMin();
        final float xmax=set.getXMax();
        if (xmin < mXChartMin)         mXChartMin=xmin;
        if (xmax > mXChartMax)         mXChartMax=xmax;
      }
    }
  }
  mDeltaX=Math.abs(mXChartMax - mXChartMin);
}
Program: 26430
Project: 26430
Buggy source:
@Override public void calculateOffsets(){
  super.calculateOffsets();
  if (mDataNotSet)   return;
  float diameter=getDiameter();
  float boxSize=diameter / 2f;
  PointF c=getCenterOffsets();
  mCircleBox.set(c.x - boxSize,c.y - boxSize,c.x + boxSize,c.y + boxSize);
}

Fixed version (ground truth):
@Override public void calculateOffsets(){
  super.calculateOffsets();
  if (mDataNotSet)   return;
  float diameter=getDiameter();
  float radius=diameter / 2f;
  PointF c=getCenterOffsets();
  final List<PieDataSet> dataSets=mData.getDataSets();
  float maxShift=0.f;
  for (int i=0; i < dataSets.size(); i++) {
    final float shift=dataSets.get(i).getSelectionShift();
    if (shift > maxShift)     maxShift=shift;
  }
  final float halfMaxShift=maxShift / 2.f;
  mCircleBox.set(c.x - radius + halfMaxShift,c.y - radius + halfMaxShift,c.x + radius - halfMaxShift,c.y + radius - halfMaxShift);
}
Program: 26431
Project: 26431
Buggy source:
@Override protected void calcMinMax(int start,int end){
  if (mYVals.size() == 0)   return;
  List<CandleEntry> entries=mYVals;
  int endValue;
  if (end == 0)   endValue=mYVals.size() - 1;
 else   endValue=end;
  mLastStart=start;
  mLastEnd=endValue;
  mYMin=mYVals.get(start).getLow();
  mYMax=mYVals.get(start).getHigh();
  for (int i=start + 1; i <= endValue; i++) {
    CandleEntry e=entries.get(i);
    if (e.getLow() < mYMin)     mYMin=e.getLow();
    if (e.getHigh() > mYMax)     mYMax=e.getHigh();
  }
}

Fixed version (ground truth):
@Override protected void calcMinMax(int start,int end){
  if (mYVals.size() == 0)   return;
  List<CandleEntry> entries=mYVals;
  int endValue;
  if (end == 0 || end >= mYVals.size())   endValue=mYVals.size() - 1;
 else   endValue=end;
  mLastStart=start;
  mLastEnd=endValue;
  mYMin=mYVals.get(start).getLow();
  mYMax=mYVals.get(start).getHigh();
  for (int i=start + 1; i <= endValue; i++) {
    CandleEntry e=entries.get(i);
    if (e.getLow() < mYMin)     mYMin=e.getLow();
    if (e.getHigh() > mYMax)     mYMax=e.getHigh();
  }
}
Program: 26432
Project: 26432
Buggy source:
@Override public void drawData(Canvas c){
  BarData barData=mChart.getBarData();
  for (int i=0; i < barData.getDataSetCount(); i++) {
    BarDataSet set=barData.getDataSetByIndex(i);
    if (set.isVisible()) {
      drawDataSet(c,set,i);
    }
  }
}

Fixed version (ground truth):
@Override public void drawData(Canvas c){
  BarData barData=mChart.getBarData();
  for (int i=0; i < barData.getDataSetCount(); i++) {
    BarDataSet set=barData.getDataSetByIndex(i);
    if (set.isVisible() && set.getEntryCount() > 0) {
      drawDataSet(c,set,i);
    }
  }
}
Program: 26434
Project: 26434
Buggy source:
@Override public void drawData(Canvas c){
  BubbleData bubbleData=mChart.getBubbleData();
  for (  BubbleDataSet set : bubbleData.getDataSets()) {
    if (set.isVisible())     drawDataSet(c,set);
  }
}

Fixed version (ground truth):
@Override public void drawData(Canvas c){
  BubbleData bubbleData=mChart.getBubbleData();
  for (  BubbleDataSet set : bubbleData.getDataSets()) {
    if (set.isVisible() && set.getEntryCount() > 0)     drawDataSet(c,set);
  }
}
Program: 26436
Project: 26436
Buggy source:
@Override public void drawData(Canvas c){
  CandleData candleData=mChart.getCandleData();
  for (  CandleDataSet set : candleData.getDataSets()) {
    if (set.isVisible())     drawDataSet(c,set);
  }
}

Fixed version (ground truth):
@Override public void drawData(Canvas c){
  CandleData candleData=mChart.getCandleData();
  for (  CandleDataSet set : candleData.getDataSets()) {
    if (set.isVisible() && set.getEntryCount() > 0)     drawDataSet(c,set);
  }
}
Program: 26438
Project: 26438
Buggy source:
@Override public void drawValues(Canvas c){
  if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) {
    List<CandleDataSet> dataSets=mChart.getCandleData().getDataSets();
    for (int i=0; i < dataSets.size(); i++) {
      CandleDataSet dataSet=dataSets.get(i);
      if (!dataSet.isDrawValuesEnabled())       continue;
      applyValueTextStyle(dataSet);
      Transformer trans=mChart.getTransformer(dataSet.getAxisDependency());
      List<CandleEntry> entries=dataSet.getYVals();
      Entry entryFrom=dataSet.getEntryForXIndex(mMinX);
      Entry entryTo=dataSet.getEntryForXIndex(mMaxX);
      int minx=Math.max(dataSet.getEntryPosition(entryFrom),0);
      int maxx=Math.min(dataSet.getEntryPosition(entryTo) + 1,entries.size());
      float[] positions=trans.generateTransformedValuesCandle(entries,mAnimator.getPhaseX(),mAnimator.getPhaseY(),minx,maxx);
      float yOffset=Utils.convertDpToPixel(5f);
      for (int j=0; j < positions.length; j+=2) {
        float x=positions[j];
        float y=positions[j + 1];
        if (!mViewPortHandler.isInBoundsRight(x))         break;
        if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))         continue;
        float val=entries.get(j / 2 + minx).getHigh();
        c.drawText(dataSet.getValueFormatter().getFormattedValue(val),x,y - yOffset,mValuePaint);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void drawValues(Canvas c){
  if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) {
    List<CandleDataSet> dataSets=mChart.getCandleData().getDataSets();
    for (int i=0; i < dataSets.size(); i++) {
      CandleDataSet dataSet=dataSets.get(i);
      if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)       continue;
      applyValueTextStyle(dataSet);
      Transformer trans=mChart.getTransformer(dataSet.getAxisDependency());
      List<CandleEntry> entries=dataSet.getYVals();
      int minx=Math.max(mMinX,0);
      int maxx=Math.min(mMaxX + 1,entries.size());
      float[] positions=trans.generateTransformedValuesCandle(entries,mAnimator.getPhaseX(),mAnimator.getPhaseY(),minx,maxx);
      float yOffset=Utils.convertDpToPixel(5f);
      for (int j=0; j < positions.length; j+=2) {
        float x=positions[j];
        float y=positions[j + 1];
        if (!mViewPortHandler.isInBoundsRight(x))         break;
        if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))         continue;
        float val=entries.get(j / 2 + minx).getHigh();
        c.drawText(dataSet.getValueFormatter().getFormattedValue(val),x,y - yOffset,mValuePaint);
      }
    }
  }
}
Program: 26440
Project: 26440
Buggy source:
@Override public void drawData(Canvas c){
  int width=(int)mViewPortHandler.getChartWidth();
  int height=(int)mViewPortHandler.getChartHeight();
  if (mDrawBitmap == null || (mDrawBitmap.getWidth() != width) || (mDrawBitmap.getHeight() != height)) {
    if (width > 0 && height > 0) {
      mDrawBitmap=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_4444);
      mBitmapCanvas=new Canvas(mDrawBitmap);
    }
 else     return;
  }
  mDrawBitmap.eraseColor(Color.TRANSPARENT);
  LineData lineData=mChart.getLineData();
  for (  LineDataSet set : lineData.getDataSets()) {
    if (set.isVisible())     drawDataSet(c,set);
  }
  c.drawBitmap(mDrawBitmap,0,0,mRenderPaint);
}

Fixed version (ground truth):
@Override public void drawData(Canvas c){
  int width=(int)mViewPortHandler.getChartWidth();
  int height=(int)mViewPortHandler.getChartHeight();
  if (mDrawBitmap == null || (mDrawBitmap.getWidth() != width) || (mDrawBitmap.getHeight() != height)) {
    if (width > 0 && height > 0) {
      mDrawBitmap=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_4444);
      mBitmapCanvas=new Canvas(mDrawBitmap);
    }
 else     return;
  }
  mDrawBitmap.eraseColor(Color.TRANSPARENT);
  LineData lineData=mChart.getLineData();
  for (  LineDataSet set : lineData.getDataSets()) {
    if (set.isVisible() && set.getEntryCount() > 0)     drawDataSet(c,set);
  }
  c.drawBitmap(mDrawBitmap,0,0,mRenderPaint);
}
Program: 26441
Project: 26441
Buggy source:
@Override public void drawValues(Canvas c){
  if (mChart.getLineData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) {
    List<LineDataSet> dataSets=mChart.getLineData().getDataSets();
    for (int i=0; i < dataSets.size(); i++) {
      LineDataSet dataSet=dataSets.get(i);
      if (!dataSet.isDrawValuesEnabled())       continue;
      applyValueTextStyle(dataSet);
      Transformer trans=mChart.getTransformer(dataSet.getAxisDependency());
      int valOffset=(int)(dataSet.getCircleSize() * 1.75f);
      if (!dataSet.isDrawCirclesEnabled())       valOffset=valOffset / 2;
      List<Entry> entries=dataSet.getYVals();
      Entry entryFrom=dataSet.getEntryForXIndex(mMinX);
      Entry entryTo=dataSet.getEntryForXIndex(mMaxX);
      int minx=Math.max(dataSet.getEntryPosition(entryFrom),0);
      int maxx=Math.min(dataSet.getEntryPosition(entryTo) + 1,entries.size());
      float[] positions=trans.generateTransformedValuesLine(entries,mAnimator.getPhaseX(),mAnimator.getPhaseY(),minx,maxx);
      for (int j=0; j < positions.length; j+=2) {
        float x=positions[j];
        float y=positions[j + 1];
        if (!mViewPortHandler.isInBoundsRight(x))         break;
        if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))         continue;
        float val=entries.get(j / 2 + minx).getVal();
        c.drawText(dataSet.getValueFormatter().getFormattedValue(val),x,y - valOffset,mValuePaint);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void drawValues(Canvas c){
  if (mChart.getLineData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) {
    List<LineDataSet> dataSets=mChart.getLineData().getDataSets();
    for (int i=0; i < dataSets.size(); i++) {
      LineDataSet dataSet=dataSets.get(i);
      if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)       continue;
      applyValueTextStyle(dataSet);
      Transformer trans=mChart.getTransformer(dataSet.getAxisDependency());
      int valOffset=(int)(dataSet.getCircleSize() * 1.75f);
      if (!dataSet.isDrawCirclesEnabled())       valOffset=valOffset / 2;
      List<Entry> entries=dataSet.getYVals();
      Entry entryFrom=dataSet.getEntryForXIndex(mMinX);
      Entry entryTo=dataSet.getEntryForXIndex(mMaxX);
      int minx=Math.max(dataSet.getEntryPosition(entryFrom),0);
      int maxx=Math.min(dataSet.getEntryPosition(entryTo) + 1,entries.size());
      float[] positions=trans.generateTransformedValuesLine(entries,mAnimator.getPhaseX(),mAnimator.getPhaseY(),minx,maxx);
      for (int j=0; j < positions.length; j+=2) {
        float x=positions[j];
        float y=positions[j + 1];
        if (!mViewPortHandler.isInBoundsRight(x))         break;
        if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))         continue;
        float val=entries.get(j / 2 + minx).getVal();
        c.drawText(dataSet.getValueFormatter().getFormattedValue(val),x,y - valOffset,mValuePaint);
      }
    }
  }
}
Program: 26442
Project: 26442
Buggy source:
@Override public void drawData(Canvas c){
  int width=(int)mViewPortHandler.getChartWidth();
  int height=(int)mViewPortHandler.getChartHeight();
  if (mDrawBitmap == null || (mDrawBitmap.getWidth() != width) || (mDrawBitmap.getHeight() != height)) {
    if (width > 0 && height > 0) {
      mDrawBitmap=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_4444);
      mBitmapCanvas=new Canvas(mDrawBitmap);
    }
 else     return;
  }
  mDrawBitmap.eraseColor(Color.TRANSPARENT);
  PieData pieData=mChart.getData();
  for (  PieDataSet set : pieData.getDataSets()) {
    if (set.isVisible())     drawDataSet(c,set);
  }
}

Fixed version (ground truth):
@Override public void drawData(Canvas c){
  int width=(int)mViewPortHandler.getChartWidth();
  int height=(int)mViewPortHandler.getChartHeight();
  if (mDrawBitmap == null || (mDrawBitmap.getWidth() != width) || (mDrawBitmap.getHeight() != height)) {
    if (width > 0 && height > 0) {
      mDrawBitmap=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_4444);
      mBitmapCanvas=new Canvas(mDrawBitmap);
    }
 else     return;
  }
  mDrawBitmap.eraseColor(Color.TRANSPARENT);
  PieData pieData=mChart.getData();
  for (  PieDataSet set : pieData.getDataSets()) {
    if (set.isVisible() && set.getEntryCount() > 0)     drawDataSet(c,set);
  }
}
Program: 26443
Project: 26443
Buggy source:
@Override public void drawData(Canvas c){
  RadarData radarData=mChart.getData();
  for (  RadarDataSet set : radarData.getDataSets()) {
    if (set.isVisible())     drawDataSet(c,set);
  }
}

Fixed version (ground truth):
@Override public void drawData(Canvas c){
  RadarData radarData=mChart.getData();
  for (  RadarDataSet set : radarData.getDataSets()) {
    if (set.isVisible() && set.getEntryCount() > 0)     drawDataSet(c,set);
  }
}
Program: 26444
Project: 26444
Buggy source:
@Override public void drawValues(Canvas c){
  float sliceangle=mChart.getSliceAngle();
  float factor=mChart.getFactor();
  PointF center=mChart.getCenterOffsets();
  float yoffset=Utils.convertDpToPixel(5f);
  for (int i=0; i < mChart.getData().getDataSetCount(); i++) {
    RadarDataSet dataSet=mChart.getData().getDataSetByIndex(i);
    if (!dataSet.isDrawValuesEnabled())     continue;
    applyValueTextStyle(dataSet);
    List<Entry> entries=dataSet.getYVals();
    for (int j=0; j < entries.size(); j++) {
      Entry e=entries.get(j);
      PointF p=Utils.getPosition(center,(e.getVal() - mChart.getYChartMin()) * factor,sliceangle * j + mChart.getRotationAngle());
      c.drawText(dataSet.getValueFormatter().getFormattedValue(e.getVal()),p.x,p.y - yoffset,mValuePaint);
    }
  }
}

Fixed version (ground truth):
@Override public void drawValues(Canvas c){
  float sliceangle=mChart.getSliceAngle();
  float factor=mChart.getFactor();
  PointF center=mChart.getCenterOffsets();
  float yoffset=Utils.convertDpToPixel(5f);
  for (int i=0; i < mChart.getData().getDataSetCount(); i++) {
    RadarDataSet dataSet=mChart.getData().getDataSetByIndex(i);
    if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)     continue;
    applyValueTextStyle(dataSet);
    List<Entry> entries=dataSet.getYVals();
    for (int j=0; j < entries.size(); j++) {
      Entry e=entries.get(j);
      PointF p=Utils.getPosition(center,(e.getVal() - mChart.getYChartMin()) * factor,sliceangle * j + mChart.getRotationAngle());
      c.drawText(dataSet.getValueFormatter().getFormattedValue(e.getVal()),p.x,p.y - yoffset,mValuePaint);
    }
  }
}
Program: 26445
Project: 26445
Buggy source:
@Override public void drawValues(Canvas c){
  if (mChart.getScatterData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) {
    List<ScatterDataSet> dataSets=mChart.getScatterData().getDataSets();
    for (int i=0; i < mChart.getScatterData().getDataSetCount(); i++) {
      ScatterDataSet dataSet=dataSets.get(i);
      if (!dataSet.isDrawValuesEnabled())       continue;
      applyValueTextStyle(dataSet);
      List<Entry> entries=dataSet.getYVals();
      float[] positions=mChart.getTransformer(dataSet.getAxisDependency()).generateTransformedValuesScatter(entries,mAnimator.getPhaseY());
      float shapeSize=dataSet.getScatterShapeSize();
      for (int j=0; j < positions.length * mAnimator.getPhaseX(); j+=2) {
        if (!mViewPortHandler.isInBoundsRight(positions[j]))         break;
        if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1])))         continue;
        float val=entries.get(j / 2).getVal();
        c.drawText(dataSet.getValueFormatter().getFormattedValue(val),positions[j],positions[j + 1] - shapeSize,mValuePaint);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void drawValues(Canvas c){
  if (mChart.getScatterData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) {
    List<ScatterDataSet> dataSets=mChart.getScatterData().getDataSets();
    for (int i=0; i < mChart.getScatterData().getDataSetCount(); i++) {
      ScatterDataSet dataSet=dataSets.get(i);
      if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)       continue;
      applyValueTextStyle(dataSet);
      List<Entry> entries=dataSet.getYVals();
      float[] positions=mChart.getTransformer(dataSet.getAxisDependency()).generateTransformedValuesScatter(entries,mAnimator.getPhaseY());
      float shapeSize=dataSet.getScatterShapeSize();
      for (int j=0; j < positions.length * mAnimator.getPhaseX(); j+=2) {
        if (!mViewPortHandler.isInBoundsRight(positions[j]))         break;
        if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1])))         continue;
        float val=entries.get(j / 2).getVal();
        c.drawText(dataSet.getValueFormatter().getFormattedValue(val),positions[j],positions[j + 1] - shapeSize,mValuePaint);
      }
    }
  }
}
Program: 26446
Project: 26446
Buggy source:
@Override public void onValueSelected(Entry e,int dataSetIndex,Highlight h){
  BarEntry entry=(BarEntry)e;
  if (entry.isStacked())   Log.i("String_Node_Str","String_Node_Str" + entry.getVals()[h.getStackIndex()]);
 else   Log.i("String_Node_Str","String_Node_Str" + entry.getVal());
}

Fixed version (ground truth):
@Override public void onValueSelected(Entry e,int dataSetIndex,Highlight h){
  BarEntry entry=(BarEntry)e;
  if (entry.getVals() != null)   Log.i("String_Node_Str","String_Node_Str" + entry.getVals()[h.getStackIndex()]);
 else   Log.i("String_Node_Str","String_Node_Str" + entry.getVal());
}
Program: 26451
Project: 26451
Buggy source:
@Override protected float getRequiredBaseOffset(){
  return mXAxis.isEnabled() ? mXAxis.mLabelWidth : Utils.convertDpToPixel(10f);
}

Fixed version (ground truth):
@Override protected float getRequiredBaseOffset(){
  return mXAxis.isEnabled() && mXAxis.isDrawLabelsEnabled() ? mXAxis.mLabelWidth : Utils.convertDpToPixel(10f);
}
Program: 26452
Project: 26452
Buggy source:
@Override protected void calcMinMax(){
  super.calcMinMax();
  float minLeft=mData.getYMin(AxisDependency.LEFT);
  float maxLeft=mData.getYMax(AxisDependency.LEFT);
  mXChartMax=mData.getXVals().size() - 1;
  mDeltaX=Math.abs(mXChartMax - mXChartMin);
  float leftRange=Math.abs(maxLeft - (mYAxis.isStartAtZeroEnabled() ? 0 : minLeft));
  float topSpaceLeft=leftRange / 100f * mYAxis.getSpaceTop();
  float bottomSpaceLeft=leftRange / 100f * mYAxis.getSpaceBottom();
  mXChartMax=mData.getXVals().size() - 1;
  mDeltaX=Math.abs(mXChartMax - mXChartMin);
  mYAxis.mAxisMaximum=!Float.isNaN(mYAxis.getAxisMaxValue()) ? mYAxis.getAxisMaxValue() : maxLeft + topSpaceLeft;
  mYAxis.mAxisMinimum=!Float.isNaN(mYAxis.getAxisMinValue()) ? mYAxis.getAxisMinValue() : minLeft - bottomSpaceLeft;
  if (mYAxis.isStartAtZeroEnabled())   mYAxis.mAxisMinimum=Math.min(0f,mYAxis.mAxisMinimum);
  mYAxis.mAxisRange=Math.abs(mYAxis.mAxisMaximum - mYAxis.mAxisMinimum);
}

Fixed version (ground truth):
@Override protected void calcMinMax(){
  super.calcMinMax();
  float minLeft=mData.getYMin(AxisDependency.LEFT);
  float maxLeft=mData.getYMax(AxisDependency.LEFT);
  mXChartMax=mData.getXVals().size() - 1;
  mDeltaX=Math.abs(mXChartMax - mXChartMin);
  float leftRange=Math.abs(maxLeft - (mYAxis.isStartAtZeroEnabled() ? 0 : minLeft));
  float topSpaceLeft=leftRange / 100f * mYAxis.getSpaceTop();
  float bottomSpaceLeft=leftRange / 100f * mYAxis.getSpaceBottom();
  mXChartMax=mData.getXVals().size() - 1;
  mDeltaX=Math.abs(mXChartMax - mXChartMin);
  if (mYAxis.isStartAtZeroEnabled()) {
    if (minLeft < 0.f && maxLeft < 0.f) {
      mYAxis.mAxisMinimum=Math.min(0.f,!Float.isNaN(mYAxis.getAxisMinValue()) ? mYAxis.getAxisMinValue() : (minLeft - bottomSpaceLeft));
      mYAxis.mAxisMaximum=0.f;
    }
 else     if (minLeft >= 0.0) {
      mYAxis.mAxisMinimum=0.f;
      mYAxis.mAxisMaximum=Math.max(0.f,!Float.isNaN(mYAxis.getAxisMaxValue()) ? mYAxis.getAxisMaxValue() : (maxLeft + topSpaceLeft));
    }
 else {
      mYAxis.mAxisMinimum=Math.min(0.f,!Float.isNaN(mYAxis.getAxisMinValue()) ? mYAxis.getAxisMinValue() : (minLeft - bottomSpaceLeft));
      mYAxis.mAxisMaximum=Math.max(0.f,!Float.isNaN(mYAxis.getAxisMaxValue()) ? mYAxis.getAxisMaxValue() : (maxLeft + topSpaceLeft));
    }
  }
 else {
    mYAxis.mAxisMinimum=!Float.isNaN(mYAxis.getAxisMinValue()) ? mYAxis.getAxisMinValue() : (minLeft - bottomSpaceLeft);
    mYAxis.mAxisMaximum=!Float.isNaN(mYAxis.getAxisMaxValue()) ? mYAxis.getAxisMaxValue() : (maxLeft + topSpaceLeft);
  }
  mYAxis.mAxisRange=Math.abs(mYAxis.mAxisMaximum - mYAxis.mAxisMinimum);
}
Program: 26453
Project: 26453
Buggy source:
private void setData(int count,float range){
  ArrayList<String> xVals=new ArrayList<String>();
  for (int i=0; i < count; i++) {
    xVals.add(mMonths[i % 12]);
  }
  ArrayList<BarEntry> yVals1=new ArrayList<BarEntry>();
  for (int i=0; i < count; i++) {
    float mult=(range + 1);
    float val=(float)(Math.random() * mult);
    yVals1.add(new BarEntry(val,i));
  }
  BarDataSet set1=new BarDataSet(yVals1,"String_Node_Str");
  set1.setBarSpacePercent(35f);
  ArrayList<BarDataSet> dataSets=new ArrayList<BarDataSet>();
  dataSets.add(set1);
  BarData data=new BarData(xVals,dataSets);
  data.setValueTextSize(10f);
  data.setValueTypeface(tf);
  mChart.setDrawValueAboveBar(false);
  mChart.setData(data);
}

Fixed version (ground truth):
private void setData(int count,float range){
  ArrayList<BarEntry> yVals1=new ArrayList<BarEntry>();
  ArrayList<String> xVals=new ArrayList<String>();
  for (int i=0; i < count; i++) {
    xVals.add(mMonths[i % 12]);
    yVals1.add(new BarEntry((float)(Math.random() * range),i));
  }
  BarDataSet set1=new BarDataSet(yVals1,"String_Node_Str");
  ArrayList<BarDataSet> dataSets=new ArrayList<BarDataSet>();
  dataSets.add(set1);
  BarData data=new BarData(xVals,dataSets);
  data.setValueTextSize(10f);
  data.setValueTypeface(tf);
  mChart.setData(data);
}
Program: 26456
Project: 26456
Buggy source:
/** 
 * Transforms an List of Entry into a float array containing the x and y values transformed with all matrices for the BARCHART.
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesBarChart(List<? extends Entry> entries,int dataSet,BarData bd,float phaseY){
  float[] valuePoints=new float[entries.size() * 2];
  int setCount=bd.getDataSetCount();
  float space=bd.getGroupSpace();
  for (int j=0; j < valuePoints.length; j+=2) {
    Entry e=entries.get(j / 2);
    float x=e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet+ space * (j / 2) + space / 2f;
    float y=e.getVal();
    valuePoints[j]=x;
    valuePoints[j + 1]=y * phaseY;
  }
  getValueToPixelMatrix().mapPoints(valuePoints);
  return valuePoints;
}

Fixed version (ground truth):
/** 
 * Transforms an List of Entry into a float array containing the x and y values transformed with all matrices for the BARCHART.
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesBarChart(List<? extends Entry> entries,int dataSet,BarData bd,float phaseY){
  float[] valuePoints=new float[entries.size() * 2];
  int setCount=bd.getDataSetCount();
  float space=bd.getGroupSpace();
  for (int j=0; j < valuePoints.length; j+=2) {
    Entry e=entries.get(j / 2);
    int i=e.getXIndex();
    float x=e.getXIndex() + i * (setCount - 1) + dataSet + space * i + space / 2f;
    float y=e.getVal();
    valuePoints[j]=x;
    valuePoints[j + 1]=y * phaseY;
  }
  getValueToPixelMatrix().mapPoints(valuePoints);
  return valuePoints;
}
Program: 26457
Project: 26457
Buggy source:
/** 
 * Transforms an List of Entry into a float array containing the x and y values transformed with all matrices for the BARCHART.
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesHorizontalBarChart(List<? extends Entry> entries,int dataSet,BarData bd,float phaseY){
  float[] valuePoints=new float[entries.size() * 2];
  int setCount=bd.getDataSetCount();
  float space=bd.getGroupSpace();
  for (int j=0; j < valuePoints.length; j+=2) {
    Entry e=entries.get(j / 2);
    float x=e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet+ space * (j / 2) + space / 2f;
    float y=e.getVal();
    valuePoints[j]=y * phaseY;
    valuePoints[j + 1]=x;
  }
  getValueToPixelMatrix().mapPoints(valuePoints);
  return valuePoints;
}

Fixed version (ground truth):
/** 
 * Transforms an List of Entry into a float array containing the x and y values transformed with all matrices for the BARCHART.
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesHorizontalBarChart(List<? extends Entry> entries,int dataSet,BarData bd,float phaseY){
  float[] valuePoints=new float[entries.size() * 2];
  int setCount=bd.getDataSetCount();
  float space=bd.getGroupSpace();
  for (int j=0; j < valuePoints.length; j+=2) {
    Entry e=entries.get(j / 2);
    int i=e.getXIndex();
    float x=e.getXIndex() + i * (setCount - 1) + dataSet + space * i + space / 2f;
    float y=e.getVal();
    valuePoints[j]=y * phaseY;
    valuePoints[j + 1]=x;
  }
  getValueToPixelMatrix().mapPoints(valuePoints);
  return valuePoints;
}
Program: 26458
Project: 26458
Buggy source:
@Override public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.actionToggleLineValues:
{
      for (      DataSet<?> set : mChart.getData().getDataSets()) {
        if (set instanceof LineDataSet)         set.setDrawValues(!set.isDrawValuesEnabled());
      }
      mChart.invalidate();
      break;
    }
case R.id.actionToggleBarValues:
{
    for (    DataSet<?> set : mChart.getData().getDataSets()) {
      if (set instanceof BarDataSet)       set.setDrawValues(!set.isDrawValuesEnabled());
    }
    mChart.invalidate();
    break;
  }
}
return true;
}

Fixed version (ground truth):
@Override public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.actionToggleLineValues:
{
      for (      DataSet<?> set : mChart.getData().getDataSets()) {
        if (set instanceof LineDataSet)         set.setDrawValues(!set.isDrawValuesEnabled());
      }
      mChart.invalidate();
      break;
    }
case R.id.actionToggleBarValues:
{
    CombinedData data=new CombinedData(mMonths);
    data.setData(generateLineData());
    mChart.setData(data);
    mChart.invalidate();
    break;
  }
}
return true;
}
Program: 26459
Project: 26459
Buggy source:
/** 
 * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail objects give information about the value at the selected index and the DataSet it belongs to. INFORMATION: This method does calculations at runtime. Do not over-use in performance critical situations.
 * @return
 */
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex){
  List<SelectionDetail> vals=new ArrayList<SelectionDetail>();
  float[] pts=new float[2];
  for (int i=0; i < mData.getDataSetCount(); i++) {
    DataSet<?> dataSet=mData.getDataSetByIndex(i);
    if (!dataSet.isHighlightEnabled())     continue;
    float yVal=dataSet.getYValForXIndex(xIndex);
    pts[1]=yVal;
    getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
    if (!Float.isNaN(pts[1])) {
      vals.add(new SelectionDetail(pts[1],i,dataSet));
    }
  }
  return vals;
}

Fixed version (ground truth):
/** 
 * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail objects give information about the value at the selected index and the DataSet it belongs to. INFORMATION: This method does calculations at runtime. Do not over-use in performance critical situations.
 * @return
 */
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex){
  List<SelectionDetail> vals=new ArrayList<SelectionDetail>();
  float[] pts=new float[2];
  for (int i=0; i < mData.getDataSetCount(); i++) {
    DataSet<?> dataSet=mData.getDataSetByIndex(i);
    if (!dataSet.isHighlightEnabled())     continue;
    final float yVal=dataSet.getYValForXIndex(xIndex);
    if (yVal == Float.NaN)     continue;
    pts[1]=yVal;
    getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);
    if (!Float.isNaN(pts[1])) {
      vals.add(new SelectionDetail(pts[1],i,dataSet));
    }
  }
  return vals;
}
Program: 26460
Project: 26460
Buggy source:
/** 
 * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail objects give information about the value at the selected index and the DataSet it belongs to. INFORMATION: This method does calculations at runtime. Do not over-use in performance critical situations.
 * @return
 */
public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex){
  List<SelectionDetail> vals=new ArrayList<SelectionDetail>();
  for (int i=0; i < mData.getDataSetCount(); i++) {
    DataSet<?> dataSet=mData.getDataSetByIndex(i);
    float yVal=dataSet.getYValForXIndex(xIndex);
    if (!Float.isNaN(yVal)) {
      vals.add(new SelectionDetail(yVal,i,dataSet));
    }
  }
  return vals;
}

Fixed version (ground truth):
/** 
 * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail objects give information about the value at the selected index and the DataSet it belongs to. INFORMATION: This method does calculations at runtime. Do not over-use in performance critical situations.
 * @return
 */
public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex){
  List<SelectionDetail> vals=new ArrayList<SelectionDetail>();
  for (int i=0; i < mData.getDataSetCount(); i++) {
    DataSet<?> dataSet=mData.getDataSetByIndex(i);
    final float yVal=dataSet.getYValForXIndex(xIndex);
    if (yVal == Float.NaN)     continue;
    vals.add(new SelectionDetail(yVal,i,dataSet));
  }
  return vals;
}
Program: 26461
Project: 26461
Buggy source:
@Override public void drawHighlighted(Canvas c,Highlight[] indices){
  for (int i=0; i < indices.length; i++) {
    LineDataSet set=mChart.getLineData().getDataSetByIndex(indices[i].getDataSetIndex());
    if (set == null || !set.isHighlightEnabled())     continue;
    mHighlightPaint.setColor(set.getHighLightColor());
    int xIndex=indices[i].getXIndex();
    if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())     continue;
    float yValue=set.getYValForXIndex(xIndex);
    if (yValue == Float.NaN)     continue;
    float y=yValue * mAnimator.getPhaseY();
    float[] pts=new float[]{xIndex,mChart.getYChartMax(),xIndex,mChart.getYChartMin(),mChart.getXChartMin(),y,mChart.getXChartMax(),y};
    mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
    c.drawLines(pts,mHighlightPaint);
  }
}

Fixed version (ground truth):
@Override public void drawHighlighted(Canvas c,Highlight[] indices){
  for (int i=0; i < indices.length; i++) {
    LineDataSet set=mChart.getLineData().getDataSetByIndex(indices[i].getDataSetIndex());
    if (set == null || !set.isHighlightEnabled())     continue;
    mHighlightPaint.setColor(set.getHighLightColor());
    int xIndex=indices[i].getXIndex();
    if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())     continue;
    final float yVal=set.getYValForXIndex(xIndex);
    if (yVal == Float.NaN)     continue;
    float y=yVal * mAnimator.getPhaseY();
    float[] pts=new float[]{xIndex,mChart.getYChartMax(),xIndex,mChart.getYChartMin(),mChart.getXChartMin(),y,mChart.getXChartMax(),y};
    mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
    c.drawLines(pts,mHighlightPaint);
  }
}
Program: 26462
Project: 26462
Buggy source:
@Override public void drawHighlighted(Canvas c,Highlight[] indices){
  for (int i=0; i < indices.length; i++) {
    ScatterDataSet set=mChart.getScatterData().getDataSetByIndex(indices[i].getDataSetIndex());
    if (set == null || !set.isHighlightEnabled())     continue;
    mHighlightPaint.setColor(set.getHighLightColor());
    int xIndex=indices[i].getXIndex();
    if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())     continue;
    float yValue=set.getYValForXIndex(xIndex);
    if (yValue == Float.NaN)     continue;
    float y=yValue * mAnimator.getPhaseY();
    float[] pts=new float[]{xIndex,mChart.getYChartMax(),xIndex,mChart.getYChartMin(),0,y,mChart.getXChartMax(),y};
    mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
    c.drawLines(pts,mHighlightPaint);
  }
}

Fixed version (ground truth):
@Override public void drawHighlighted(Canvas c,Highlight[] indices){
  for (int i=0; i < indices.length; i++) {
    ScatterDataSet set=mChart.getScatterData().getDataSetByIndex(indices[i].getDataSetIndex());
    if (set == null || !set.isHighlightEnabled())     continue;
    mHighlightPaint.setColor(set.getHighLightColor());
    int xIndex=indices[i].getXIndex();
    if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())     continue;
    final float yVal=set.getYValForXIndex(xIndex);
    if (yVal == Float.NaN)     continue;
    float y=yVal * mAnimator.getPhaseY();
    float[] pts=new float[]{xIndex,mChart.getYChartMax(),xIndex,mChart.getYChartMin(),0,y,mChart.getXChartMax(),y};
    mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);
    c.drawLines(pts,mHighlightPaint);
  }
}
Program: 26464
Project: 26464
Buggy source:
/** 
 * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.
 * @param set
 * @param xIndex
 * @param dataSetIndex
 * @param yValue
 * @return
 */
protected Highlight getStackedHighlight(BarDataSet set,int xIndex,int dataSetIndex,double yValue){
  BarEntry entry=set.getEntryForXIndex(xIndex);
  if (entry != null) {
    int stackIndex=getClosestStackIndex(entry,(float)yValue);
    Highlight h=new Highlight(xIndex,dataSetIndex,stackIndex);
    return h;
  }
 else   return null;
}

Fixed version (ground truth):
/** 
 * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.
 * @param set
 * @param xIndex
 * @param dataSetIndex
 * @param yValue
 * @return
 */
protected Highlight getStackedHighlight(BarDataSet set,int xIndex,int dataSetIndex,double yValue){
  BarEntry entry=set.getEntryForXIndex(xIndex);
  if (entry != null) {
    Range[] ranges=getRanges(entry);
    int stackIndex=getClosestStackIndex(ranges,(float)yValue);
    Highlight h=new Highlight(xIndex,dataSetIndex,stackIndex,ranges[stackIndex]);
    return h;
  }
 else   return null;
}
Program: 26465
Project: 26465
Buggy source:
/** 
 * Returns the index of the closest value inside the values array (for stacked barchart) to the value given as a parameter.
 * @param e
 * @param value
 * @return
 */
protected int getClosestStackIndex(BarEntry e,float value){
  Range[] ranges=getRanges(e);
  int stackIndex=0;
  for (  Range range : ranges) {
    if (range.contains(value))     return stackIndex;
 else     stackIndex++;
  }
  int length=ranges.length - 1;
  return (value > ranges[length].to) ? length : 0;
}

Fixed version (ground truth):
/** 
 * Returns the index of the closest value inside the values array / ranges (stacked barchart) to the value given as a parameter.
 * @param ranges
 * @param value
 * @return
 */
protected int getClosestStackIndex(Range[] ranges,float value){
  int stackIndex=0;
  for (  Range range : ranges) {
    if (range.contains(value))     return stackIndex;
 else     stackIndex++;
  }
  int length=ranges.length - 1;
  return (value > ranges[length].to) ? length : 0;
}
Program: 26466
Project: 26466
Buggy source:
protected Range[] getRanges(BarEntry entry){
  float[] values=entry.getVals();
  float negRemain=-entry.getNegativeSum();
  float posRemain=0f;
  Range[] ranges=new Range[values.length];
  for (int i=0; i < ranges.length; i++) {
    float value=values[i];
    if (value < 0) {
      ranges[i]=new Range(negRemain,negRemain + Math.abs(value));
      negRemain+=Math.abs(value);
    }
 else {
      ranges[i]=new Range(posRemain,posRemain + value);
      posRemain+=value;
    }
  }
  return ranges;
}

Fixed version (ground truth):
/** 
 * Splits up the stack-values of the given bar-entry into Range objects.
 * @param entry
 * @return
 */
protected Range[] getRanges(BarEntry entry){
  float[] values=entry.getVals();
  if (values == null)   return null;
  float negRemain=-entry.getNegativeSum();
  float posRemain=0f;
  Range[] ranges=new Range[values.length];
  for (int i=0; i < ranges.length; i++) {
    float value=values[i];
    if (value < 0) {
      ranges[i]=new Range(negRemain,negRemain + Math.abs(value));
      negRemain+=Math.abs(value);
    }
 else {
      ranges[i]=new Range(posRemain,posRemain + value);
      posRemain+=value;
    }
  }
  return ranges;
}
Program: 26467
Project: 26467
Buggy source:
/** 
 * Constructor, only used for stacked-barchart.
 * @param x the index of the highlighted value on the x-axis
 * @param val the value at the position the user touched
 * @param dataSet the index of the DataSet the highlighted value belongs to
 * @param stackIndex references which value of a stacked-bar entry has beenselected
 */
public Highlight(int x,int dataSet,int stackIndex){
  this(x,dataSet);
  mStackIndex=stackIndex;
}

Fixed version (ground truth):
/** 
 * Constructor, only used for stacked-barchart.
 * @param x the index of the highlighted value on the x-axis
 * @param dataSet the index of the DataSet the highlighted value belongs to
 * @param stackIndex references which value of a stacked-bar entry has beenselected
 * @param range the range the selected stack-value is in
 */
public Highlight(int x,int dataSet,int stackIndex,Range range){
  this(x,dataSet,stackIndex);
  this.mRange=range;
}
Program: 26473
Project: 26473
Buggy source:
/** 
 * calc minimum and maximum y value
 */
protected void calcMinMax(int start,int end){
  if (mYVals.size() == 0)   return;
  int endValue;
  if (end == 0)   endValue=mYVals.size() - 1;
 else   endValue=end;
  mLastStart=start;
  mLastEnd=endValue;
  mYMin=Float.MAX_VALUE;
  mYMax=-Float.MIN_VALUE;
  for (int i=start; i <= endValue; i++) {
    Entry e=mYVals.get(i);
    if (e != null && !Float.isNaN(e.getVal())) {
      if (e.getVal() < mYMin)       mYMin=e.getVal();
      if (e.getVal() > mYMax)       mYMax=e.getVal();
    }
  }
  if (mYMin == Float.MAX_VALUE) {
    mYMin=0.f;
    mYMax=0.f;
  }
}

Fixed version (ground truth):
/** 
 * calc minimum and maximum y value
 */
protected void calcMinMax(int start,int end){
  final int yValCount=mYVals.size();
  if (yValCount == 0)   return;
  int endValue;
  if (end == 0 || end >= yValCount)   endValue=yValCount - 1;
 else   endValue=end;
  mLastStart=start;
  mLastEnd=endValue;
  mYMin=Float.MAX_VALUE;
  mYMax=-Float.MAX_VALUE;
  for (int i=start; i <= endValue; i++) {
    Entry e=mYVals.get(i);
    if (e != null && !Float.isNaN(e.getVal())) {
      if (e.getVal() < mYMin)       mYMin=e.getVal();
      if (e.getVal() > mYMax)       mYMax=e.getVal();
    }
  }
  if (mYMin == Float.MAX_VALUE) {
    mYMin=0.f;
    mYMax=0.f;
  }
}
Program: 26476
Project: 26476
Buggy source:
/** 
 * Prepares a bar for being highlighted.
 * @param x the x-position
 * @param y the y-position
 * @param barspace the space between bars
 * @param from
 * @param trans
 */
protected void prepareBarHighlight(float x,float y,float barspaceHalf,float from,Transformer trans){
  float barWidth=0.5f;
  float left=x - barWidth + barspaceHalf;
  float right=x + barWidth - barspaceHalf;
  float top=y >= from ? y : from;
  float bottom=y <= from ? y : from;
  mBarRect.set(left,top,right,bottom);
  trans.rectValueToPixel(mBarRect,mAnimator.getPhaseY());
}

Fixed version (ground truth):
/** 
 * Prepares a bar for being highlighted.
 * @param x the x-position
 * @param y the y-position
 * @param barspaceHalf the space between bars
 * @param from
 * @param trans
 */
protected void prepareBarHighlight(float x,float y,float barspaceHalf,float from,Transformer trans){
  float barWidth=0.5f;
  float left=x - barWidth + barspaceHalf;
  float right=x + barWidth - barspaceHalf;
  float top=y >= from ? y : from;
  float bottom=y <= from ? y : from;
  mBarRect.set(left,top,right,bottom);
  trans.rectValueToPixel(mBarRect,mAnimator.getPhaseY());
}