Program: 18367
Project: 18367
Buggy source:
@Override public void calculateOffsets(){
  float legendLeft=0f, legendRight=0f, legendBottom=0f, legendTop=0f;
  if (mLegend != null && mLegend.isEnabled()) {
    float fullLegendWidth=Math.min(mLegend.mNeededWidth,mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent()) + mLegend.getFormSize() + mLegend.getFormToTextSpace();
    if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART_CENTER) {
      float spacing=Utils.convertDpToPixel(13f);
      legendRight=fullLegendWidth + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=fullLegendWidth + 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=fullLegendWidth + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=fullLegendWidth + 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) {
      float yOffset=getRequiredBottomOffset();
      legendBottom=Math.min(mLegend.mNeededHeight + yOffset,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
    }
    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);
    }
  }
  legendTop+=getExtraTopOffset();
  legendRight+=getExtraRightOffset();
  legendBottom+=getExtraBottomOffset();
  legendLeft+=getExtraLeftOffset();
  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 public void calculateOffsets(){
  float legendLeft=0f, legendRight=0f, legendBottom=0f, legendTop=0f;
  if (mLegend != null && mLegend.isEnabled()) {
    float fullLegendWidth=Math.min(mLegend.mNeededWidth,mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent()) + mLegend.getFormSize() + mLegend.getFormToTextSpace();
    if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART_CENTER) {
      float spacing=Utils.convertDpToPixel(13f);
      legendRight=fullLegendWidth + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=fullLegendWidth + 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=fullLegendWidth + spacing;
    }
 else     if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART) {
      float spacing=Utils.convertDpToPixel(8f);
      float legendWidth=fullLegendWidth + 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) {
      float yOffset=getRequiredBottomOffset();
      legendBottom=Math.min(mLegend.mNeededHeight + yOffset,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
    }
    legendLeft+=getRequiredBaseOffset();
    legendRight+=getRequiredBaseOffset();
    legendTop+=getRequiredBaseOffset();
  }
  float min=Utils.convertDpToPixel(10f);
  if (this instanceof RadarChart) {
    XAxis x=((RadarChart)this).getXAxis();
    if (x.isEnabled() && x.isDrawLabelsEnabled()) {
      min=Math.max(Utils.convertDpToPixel(10f),x.mLabelWidth);
    }
  }
  legendTop+=getExtraTopOffset();
  legendRight+=getExtraRightOffset();
  legendBottom+=getExtraBottomOffset();
  legendLeft+=getExtraLeftOffset();
  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);
}