Program: 26889
Project: 26889
Buggy source:
/** 
 * draws the legend
 */
protected void drawLegend(){
  if (!mDrawLegend || mLegend == null)   return;
  String[] labels=mLegend.getLegendLabels();
  Typeface tf=mLegend.getTypeface();
  if (tf != null)   mLegendLabelPaint.setTypeface(tf);
  mLegendLabelPaint.setTextSize(mLegend.getTextSize());
  mLegendLabelPaint.setColor(mLegend.getTextColor());
  float formSize=mLegend.getFormSize();
  float formTextSpaceAndForm=mLegend.getFormToTextSpace() + formSize;
  float stackSpace=mLegend.getStackSpace();
  float textSize=mLegend.getTextSize();
  float textDrop=(Utils.calcTextHeight(mLegendLabelPaint,"String_Node_Str") + formSize) / 2f;
  float posX, posY;
switch (mLegend.getPosition()) {
case BELOW_CHART_LEFT:
    posX=mLegend.getOffsetLeft();
  posY=getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f;
for (int i=0; i < labels.length; i++) {
  mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
  if (labels[i] != null) {
    if (mLegend.getColors()[i] != -2)     posX+=formTextSpaceAndForm;
    mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
    posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + mLegend.getXEntrySpace();
  }
 else {
    posX+=formSize + stackSpace;
  }
}
break;
case BELOW_CHART_RIGHT:
posX=getWidth() - getOffsetRight();
posY=getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f;
for (int i=labels.length - 1; i >= 0; i--) {
if (labels[i] != null) {
posX-=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + mLegend.getXEntrySpace();
mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
if (mLegend.getColors()[i] != -2) posX-=formTextSpaceAndForm;
}
 else {
posX-=stackSpace + formSize;
}
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
}
break;
case RIGHT_OF_CHART:
posX=getWidth() - mLegend.getMaximumEntryLength(mLegendLabelPaint) - formTextSpaceAndForm;
posY=mLegend.getOffsetTop();
float stack=0f;
boolean wasStacked=false;
for (int i=0; i < labels.length; i++) {
mLegend.drawForm(mDrawCanvas,posX + stack,posY,mLegendFormPaint,i);
if (labels[i] != null) {
if (!wasStacked) {
float x=posX;
if (mLegend.getColors()[i] != -2) x+=formTextSpaceAndForm;
posY+=textDrop;
mLegend.drawLabel(mDrawCanvas,x,posY,mLegendLabelPaint,i);
}
 else {
posY+=textSize * 1.2f + formSize;
mLegend.drawLabel(mDrawCanvas,posX,posY,mLegendLabelPaint,i);
}
posY+=mLegend.getYEntrySpace();
stack=0f;
}
 else {
stack+=formSize + stackSpace;
wasStacked=true;
}
}
break;
case BELOW_CHART_CENTER:
float fullSize=mLegend.getFullWidth(mLegendLabelPaint);
posX=getWidth() / 2f - fullSize / 2f;
posY=getHeight() - mLegend.getOffsetBottom() / 2f - formSize;
for (int i=0; i < labels.length; i++) {
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
if (labels[i] != null) {
if (mLegend.getColors()[i] != -2) posX+=formTextSpaceAndForm;
mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + mLegend.getXEntrySpace();
}
 else {
posX+=formSize + stackSpace;
}
}
break;
}
}

Fixed version (ground truth):
/** 
 * draws the legend
 */
protected void drawLegend(){
  if (!mDrawLegend || mLegend == null)   return;
  String[] labels=mLegend.getLegendLabels();
  Typeface tf=mLegend.getTypeface();
  if (tf != null)   mLegendLabelPaint.setTypeface(tf);
  mLegendLabelPaint.setTextSize(mLegend.getTextSize());
  mLegendLabelPaint.setColor(mLegend.getTextColor());
  float formSize=mLegend.getFormSize();
  float formTextSpaceAndForm=mLegend.getFormToTextSpace() + formSize;
  float stackSpace=mLegend.getStackSpace();
  float textSize=mLegend.getTextSize();
  float textDrop=(Utils.calcTextHeight(mLegendLabelPaint,"String_Node_Str") + formSize) / 2f;
  float posX, posY;
switch (mLegend.getPosition()) {
case BELOW_CHART_LEFT:
    posX=mLegend.getOffsetLeft();
  posY=getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f;
for (int i=0; i < labels.length; i++) {
  mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
  if (labels[i] != null) {
    if (mLegend.getColors()[i] != -2)     posX+=formTextSpaceAndForm;
    mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
    posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + mLegend.getXEntrySpace();
  }
 else {
    posX+=formSize + stackSpace;
  }
}
break;
case BELOW_CHART_RIGHT:
posX=getWidth() - getOffsetRight();
posY=getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f;
for (int i=labels.length - 1; i >= 0; i--) {
if (labels[i] != null) {
posX-=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + mLegend.getXEntrySpace();
mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
if (mLegend.getColors()[i] != -2) posX-=formTextSpaceAndForm;
}
 else {
posX-=stackSpace + formSize;
}
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
}
break;
case RIGHT_OF_CHART:
posX=getWidth() - mLegend.getMaximumEntryLength(mLegendLabelPaint) - formTextSpaceAndForm;
posY=mLegend.getOffsetTop();
float stack=0f;
boolean wasStacked=false;
for (int i=0; i < labels.length; i++) {
mLegend.drawForm(mDrawCanvas,posX + stack,posY,mLegendFormPaint,i);
if (labels[i] != null) {
if (!wasStacked) {
float x=posX;
if (mLegend.getColors()[i] != -2) x+=formTextSpaceAndForm;
posY+=textDrop;
mLegend.drawLabel(mDrawCanvas,x,posY,mLegendLabelPaint,i);
}
 else {
posY+=textSize * 1.2f + formSize;
mLegend.drawLabel(mDrawCanvas,posX,posY,mLegendLabelPaint,i);
}
posY+=mLegend.getYEntrySpace();
stack=0f;
}
 else {
stack+=formSize + stackSpace;
wasStacked=true;
}
}
break;
case BELOW_CHART_CENTER:
float fullSize=mLegend.getFullWidth(mLegendLabelPaint);
posX=getWidth() / 2f - fullSize / 2f;
posY=getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f;
for (int i=0; i < labels.length; i++) {
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
if (labels[i] != null) {
if (mLegend.getColors()[i] != -2) posX+=formTextSpaceAndForm;
mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + mLegend.getXEntrySpace();
}
 else {
posX+=formSize + stackSpace;
}
}
Log.i(LOG_TAG,"String_Node_Str" + mContentRect.bottom + "String_Node_Str"+ getHeight()+ "String_Node_Str"+ posY+ "String_Node_Str"+ formSize);
break;
}
}