Program: 26507
Project: 26507
Buggy source:
@Override protected void calculateOffsets(){
  float legendLeft=0f, legendRight=0f, legendBottom=0f, legendTop=0f;
  if (mLegend != null && mLegend.isEnabled()) {
    if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART_CENTER) {
      float spacing=Utils.convertDpToPixel(13f);
      legendRight=getFullLegendWidth() + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=getFullLegendWidth() + spacing;
      float legendHeight=mLegend.mNeededHeight + mLegend.mTextHeightMax;
      PointF c=getCenter();
      PointF bottomRight=new PointF(getWidth() - legendWidth + 15,legendHeight + 15);
      float distLegend=distanceToCenter(bottomRight.x,bottomRight.y);
      PointF reference=getPosition(c,getRadius(),getAngleForPoint(bottomRight.x,bottomRight.y));
      float distReference=distanceToCenter(reference.x,reference.y);
      float min=Utils.convertDpToPixel(5f);
      if (distLegend < distReference) {
        float diff=distReference - distLegend;
        legendRight=min + diff;
      }
      if (bottomRight.y >= c.y && getHeight() - legendWidth > getWidth()) {
        legendRight=legendWidth;
      }
    }
 else     if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART_CENTER) {
      float spacing=Utils.convertDpToPixel(13f);
      legendLeft=getFullLegendWidth() + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=getFullLegendWidth() + spacing;
      float legendHeight=mLegend.mNeededHeight + mLegend.mTextHeightMax;
      PointF c=getCenter();
      PointF bottomLeft=new PointF(legendWidth - 15,legendHeight + 15);
      float distLegend=distanceToCenter(bottomLeft.x,bottomLeft.y);
      PointF reference=getPosition(c,getRadius(),getAngleForPoint(bottomLeft.x,bottomLeft.y));
      float distReference=distanceToCenter(reference.x,reference.y);
      float min=Utils.convertDpToPixel(5f);
      if (distLegend < distReference) {
        float diff=distReference - distLegend;
        legendLeft=min + diff;
      }
      if (bottomLeft.y >= c.y && getHeight() - legendWidth > getWidth()) {
        legendLeft=legendWidth;
      }
    }
 else     if (mLegend.getPosition() == LegendPosition.BELOW_CHART_LEFT || mLegend.getPosition() == LegendPosition.BELOW_CHART_RIGHT || mLegend.getPosition() == LegendPosition.BELOW_CHART_CENTER) {
      legendBottom=getRequiredBottomOffset();
    }
    legendLeft+=getRequiredBaseOffset();
    legendRight+=getRequiredBaseOffset();
    legendTop+=getRequiredBaseOffset();
  }
  float min=Utils.convertDpToPixel(10f);
  float offsetLeft=Math.max(min,legendLeft);
  float offsetTop=Math.max(min,legendTop);
  float offsetRight=Math.max(min,legendRight);
  float offsetBottom=Math.max(min,Math.max(getRequiredBaseOffset(),legendBottom));
  mViewPortHandler.restrainViewPort(offsetLeft,offsetTop,offsetRight,offsetBottom);
  if (mLogEnabled)   Log.i(LOG_TAG,"String_Node_Str" + offsetLeft + "String_Node_Str"+ offsetTop+ "String_Node_Str"+ offsetRight+ "String_Node_Str"+ offsetBottom);
}

Fixed version (ground truth):
@Override protected void calculateOffsets(){
  float legendLeft=0f, legendRight=0f, legendBottom=0f, legendTop=0f;
  if (mLegend != null && mLegend.isEnabled()) {
    if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART_CENTER) {
      float spacing=Utils.convertDpToPixel(13f);
      legendRight=getFullLegendWidth() + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=getFullLegendWidth() + spacing;
      float legendHeight=mLegend.mNeededHeight + mLegend.mTextHeightMax;
      PointF c=getCenter();
      PointF bottomRight=new PointF(getWidth() - legendWidth + 15,legendHeight + 15);
      float distLegend=distanceToCenter(bottomRight.x,bottomRight.y);
      PointF reference=getPosition(c,getRadius(),getAngleForPoint(bottomRight.x,bottomRight.y));
      float distReference=distanceToCenter(reference.x,reference.y);
      float min=Utils.convertDpToPixel(5f);
      if (distLegend < distReference) {
        float diff=distReference - distLegend;
        legendRight=min + diff;
      }
      if (bottomRight.y >= c.y && getHeight() - legendWidth > getWidth()) {
        legendRight=legendWidth;
      }
    }
 else     if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART_CENTER) {
      float spacing=Utils.convertDpToPixel(13f);
      legendLeft=getFullLegendWidth() + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=getFullLegendWidth() + spacing;
      float legendHeight=mLegend.mNeededHeight + mLegend.mTextHeightMax;
      PointF c=getCenter();
      PointF bottomLeft=new PointF(legendWidth - 15,legendHeight + 15);
      float distLegend=distanceToCenter(bottomLeft.x,bottomLeft.y);
      PointF reference=getPosition(c,getRadius(),getAngleForPoint(bottomLeft.x,bottomLeft.y));
      float distReference=distanceToCenter(reference.x,reference.y);
      float min=Utils.convertDpToPixel(5f);
      if (distLegend < distReference) {
        float diff=distReference - distLegend;
        legendLeft=min + diff;
      }
      if (bottomLeft.y >= c.y && getHeight() - legendWidth > getWidth()) {
        legendLeft=legendWidth;
      }
    }
 else     if (mLegend.getPosition() == LegendPosition.BELOW_CHART_LEFT || mLegend.getPosition() == LegendPosition.BELOW_CHART_RIGHT || mLegend.getPosition() == LegendPosition.BELOW_CHART_CENTER) {
      legendBottom=getRequiredBottomOffset();
    }
    legendLeft+=getRequiredBaseOffset();
    legendRight+=getRequiredBaseOffset();
    legendTop+=getRequiredBaseOffset();
  }
  float min=Utils.convertDpToPixel(10f);
  if (this instanceof RadarChart) {
    XAxis x=((RadarChart)this).getXAxis();
    if (x.isEnabled()) {
      min=Math.max(Utils.convertDpToPixel(10f),x.mLabelWidth);
    }
  }
  float offsetLeft=Math.max(min,legendLeft);
  float offsetTop=Math.max(min,legendTop);
  float offsetRight=Math.max(min,legendRight);
  float offsetBottom=Math.max(min,Math.max(getRequiredBaseOffset(),legendBottom));
  mViewPortHandler.restrainViewPort(offsetLeft,offsetTop,offsetRight,offsetBottom);
  if (mLogEnabled)   Log.i(LOG_TAG,"String_Node_Str" + offsetLeft + "String_Node_Str"+ offsetTop+ "String_Node_Str"+ offsetRight+ "String_Node_Str"+ offsetBottom);
}