Program: 18945
Project: 18945
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);
  float formSize=mLegend.getFormSize();
  float formToTextSpace=mLegend.getFormToTextSpace();
  float entrySpace=mLegend.getEntrySpace();
  float textSize=Utils.convertPixelsToDp(mLegendLabelPaint.getTextSize());
  float textDrop=(textSize + formSize) / 2f;
  float posX, posY;
switch (mLegend.getPosition()) {
case BELOW_CHART_LEFT:
    posX=mOffsetLeft;
  posY=getHeight() - mOffsetBottom + textSize * 2;
for (int i=0; i < labels.length; i++) {
  mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
  posX+=formToTextSpace;
  if (labels[i] != null) {
    mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
    posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + entrySpace;
  }
}
break;
case BELOW_CHART_RIGHT:
posX=getWidth() - mOffsetRight;
posY=getHeight() - mOffsetBottom + textSize * 2;
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);
posX-=formToTextSpace;
}
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
posX-=entrySpace;
}
break;
case RIGHT_OF_CHART:
if (this instanceof BarLineChartBase) {
posX=getWidth() - mOffsetRight + formSize;
}
 else {
posX=getWidth() - mLegend.getMaximumEntryLength(mLegendLabelPaint);
}
posY=mOffsetTop;
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) {
mLegend.drawLabel(mDrawCanvas,posX + formToTextSpace,posY + textDrop,mLegendLabelPaint,i);
}
 else {
mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop + entrySpace,mLegendLabelPaint,i);
posY+=entrySpace;
}
posY+=entrySpace;
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);
  float formSize=mLegend.getFormSize();
  float formToTextSpace=mLegend.getFormToTextSpace();
  float entrySpace=mLegend.getEntrySpace();
  float textSize=Utils.convertPixelsToDp(mLegendLabelPaint.getTextSize());
  float textDrop=(textSize + formSize) / 2f + textSize / 2f;
  float posX, posY;
switch (mLegend.getPosition()) {
case BELOW_CHART_LEFT:
    posX=mOffsetLeft;
  posY=getHeight() - mOffsetBottom + textSize * 2;
for (int i=0; i < labels.length; i++) {
  mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
  posX+=formToTextSpace;
  if (labels[i] != null) {
    mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop,mLegendLabelPaint,i);
    posX+=Utils.calcTextWidth(mLegendLabelPaint,labels[i]) + entrySpace;
  }
}
break;
case BELOW_CHART_RIGHT:
posX=getWidth() - mOffsetRight;
posY=getHeight() - mOffsetBottom + textSize * 2;
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);
posX-=formToTextSpace;
}
mLegend.drawForm(mDrawCanvas,posX,posY,mLegendFormPaint,i);
posX-=entrySpace;
}
break;
case RIGHT_OF_CHART:
if (this instanceof BarLineChartBase) {
posX=getWidth() - mOffsetRight + formSize;
posY=mOffsetTop;
}
 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) {
mLegend.drawLabel(mDrawCanvas,posX + formToTextSpace,posY + textDrop,mLegendLabelPaint,i);
}
 else {
mLegend.drawLabel(mDrawCanvas,posX,posY + textDrop + entrySpace,mLegendLabelPaint,i);
posY+=entrySpace;
}
posY+=entrySpace;
stack=0f;
}
 else {
stack+=formSize + 4f;
wasStacked=true;
}
}
break;
}
}