Program: 27022
Project: 27022
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());
  float formSize=mLegend.getFormSize();
  float formToTextSpace=mLegend.getFormToTextSpace() + formSize;
  float xEntrySpace=mLegend.getXEntrySpace() + formSize;
  float yEntrySpace=mLegend.getYEntrySpace() + formSize;
  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] != -1)     posX+=formToTextSpace;
    mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
    posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + xEntrySpace;
  }
 else {
    posX+=xEntrySpace;
  }
}
break;
case BELOW_CHART_RIGHT:
posX=getWidth() - mLegend.getOffsetRight() - 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.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
if (mLegend.getColors()[i] != -1) posX-=formToTextSpace;
}
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
posX-=xEntrySpace;
}
break;
case RIGHT_OF_CHART:
if (this instanceof BarLineChartBase) {
posX=getWidth() - mLegend.getOffsetRight() + Utils.convertDpToPixel(9f);
posY=mLegend.getOffsetTop();
}
 else {
posX=getWidth() - mLegend.getMaximumEntryLength(mLegendLabelPaint);
posY=Utils.calcTextHeight(mLegendLabelPaint,"String_Node_Str") * 1.5f;
}
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] != -1) x+=formToTextSpace;
mLegend.drawLabel(mDrawCanvas,x,posY + textDrop,mLegendLabelPaint,i);
}
 else {
mLegend.drawLabel(mDrawCanvas,posX,posY + textSize + formSize+ mLegend.getYEntrySpace(),mLegendLabelPaint,i);
posY+=yEntrySpace;
}
posY+=mLegend.getYEntrySpace() + textSize;
stack=0f;
}
 else {
stack+=formSize + 4f;
wasStacked=true;
}
}
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());
  float formSize=mLegend.getFormSize();
  float formTextSpaceAndForm=mLegend.getFormToTextSpace() + formSize;
  float stackSpace=Utils.convertDpToPixel(3f);
  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] != -1)     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] != -1) 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] != -1) 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;
}
}