Program: 26417
Project: 26417
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=getRequiredLegendOffset();
      legendBottom=Math.min(mLegend.mNeededHeight + yOffset,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
    }
 else     if (mLegend.getPosition() == LegendPosition.ABOVE_CHART_LEFT || mLegend.getPosition() == LegendPosition.ABOVE_CHART_RIGHT || mLegend.getPosition() == LegendPosition.ABOVE_CHART_CENTER) {
      float yOffset=getRequiredLegendOffset();
      legendTop=Math.min(mLegend.mNeededHeight + yOffset,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
    }
    legendLeft+=getRequiredBaseOffset();
    legendRight+=getRequiredBaseOffset();
    legendTop+=getRequiredBaseOffset();
  }
  float minOffset=Utils.convertDpToPixel(mMinOffset);
  if (this instanceof RadarChart) {
    XAxis x=((RadarChart)this).getXAxis();
    if (x.isEnabled() && x.isDrawLabelsEnabled()) {
      minOffset=Math.max(minOffset,x.mLabelWidth);
    }
  }
  legendTop+=getExtraTopOffset();
  legendRight+=getExtraRightOffset();
  legendBottom+=getExtraBottomOffset();
  legendLeft+=getExtraLeftOffset();
  float offsetLeft=Math.max(minOffset,legendLeft);
  float offsetTop=Math.max(minOffset,legendTop);
  float offsetRight=Math.max(minOffset,legendRight);
  float offsetBottom=Math.max(minOffset,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=getRequiredLegendOffset();
      legendBottom=Math.min(mLegend.mNeededHeight + yOffset,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
    }
 else     if (mLegend.getPosition() == LegendPosition.ABOVE_CHART_LEFT || mLegend.getPosition() == LegendPosition.ABOVE_CHART_RIGHT || mLegend.getPosition() == LegendPosition.ABOVE_CHART_CENTER) {
      float yOffset=getRequiredLegendOffset();
      legendTop=Math.min(mLegend.mNeededHeight + yOffset,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
    }
    legendLeft+=getRequiredBaseOffset();
    legendRight+=getRequiredBaseOffset();
    legendTop+=getRequiredBaseOffset();
  }
  float minOffset=0f;
  if (this instanceof RadarChart) {
    XAxis x=((RadarChart)this).getXAxis();
    if (x.isEnabled() && x.isDrawLabelsEnabled()) {
      minOffset=x.mLabelWidth;
    }
  }
  legendTop+=getExtraTopOffset();
  legendRight+=getExtraRightOffset();
  legendBottom+=getExtraBottomOffset();
  legendLeft+=getExtraLeftOffset();
  float offsetLeft=Math.max(minOffset,legendLeft);
  float offsetTop=Math.max(minOffset,legendTop);
  float offsetRight=Math.max(minOffset,legendRight);
  float offsetBottom=Math.max(minOffset,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);
}