Program: 157480
Project: 157480
Buggy source:
/** 
 * If the canvas is null, then only touch calculations are performed to pick the target candidate.
 */
@Override protected void onDraw(Canvas canvas){
  if (canvas != null) {
    super.onDraw(canvas);
  }
  mTotalWidth=0;
  final int height=getHeight();
  if (mBgPadding == null) {
    mBgPadding=new Rect(0,0,0,0);
    if (getBackground() != null) {
      getBackground().getPadding(mBgPadding);
    }
    mDivider.setBounds(0,0,mDivider.getIntrinsicWidth(),mDivider.getIntrinsicHeight());
  }
  final int dividerYOffest=(height - mDivider.getMinimumHeight()) / 2;
  final int count=mSuggestions.size();
  final Rect bgPadding=mBgPadding;
  final Paint paint=mPaint;
  final int touchX=mTouchX;
  final int scrollX=getScrollX();
  final boolean scrolled=mScrolled;
  final boolean typedWordValid=mTypedWordValid;
  int x=0;
  for (int i=0; i < count; i++) {
    CharSequence suggestion=mSuggestions.get(i);
    if (suggestion == null)     continue;
    final int wordLength=suggestion.length();
    paint.setColor(mColorNormal);
    if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setColor(mColorRecommended);
    }
 else     if (i != 0 || (wordLength == 1 && count > 1)) {
      paint.setColor(mColorOther);
    }
    int wordWidth;
    if ((wordWidth=mWordWidth[i]) == 0) {
      float textWidth=paint.measureText(suggestion,0,wordLength);
      wordWidth=(int)(textWidth + mXGap * 2);
      mWordWidth[i]=wordWidth;
    }
    mWordX[i]=x;
    if (touchX != OUT_OF_BOUNDS_X_COORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) {
      if (canvas != null && !mShowingAddToDictionary) {
        canvas.translate(x,0);
        mSelectionHighlight.setBounds(0,bgPadding.top,wordWidth,height);
        mSelectionHighlight.draw(canvas);
        canvas.translate(-x,0);
      }
      mSelectedString=suggestion;
      mSelectedIndex=i;
    }
    if (canvas != null) {
      if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
        final int y=(int)(height + mPaint.getTextSize() - mPaint.descent()) / 2;
        canvas.drawText(suggestion,0,wordLength,x + wordWidth / 2,y,paint);
      }
 else {
        final int y=(int)(height - mPaint.getTextSize() + mPaint.descent()) / 2;
        float textX=x + (wordWidth / 2) - mXGap;
        float textY=y - bgPadding.bottom - bgPadding.top;
        canvas.translate(textX,textY);
        mTextPaint.setTypeface(paint.getTypeface());
        mTextPaint.setColor(paint.getColor());
        StaticLayout suggestionText=new StaticLayout(suggestion,mTextPaint,wordWidth,Alignment.ALIGN_CENTER,0.0f,0.0f,false);
        suggestionText.draw(canvas);
        canvas.translate(-textX,-textY);
      }
      paint.setColor(mColorOther);
      canvas.translate(x + wordWidth,0);
      if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) {
        canvas.translate(0,dividerYOffest);
        mDivider.draw(canvas);
        canvas.translate(0,-dividerYOffest);
      }
      canvas.translate(-x - wordWidth,0);
    }
    paint.setTypeface(Typeface.DEFAULT);
    x+=wordWidth;
  }
  mTotalWidth=x;
  if (mTargetScrollX != scrollX) {
    scrollToTarget();
  }
}

Fixed version (ground truth):
/** 
 * If the canvas is null, then only touch calculations are performed to pick the target candidate.
 */
@Override protected void onDraw(Canvas canvas){
  if (canvas != null) {
    super.onDraw(canvas);
  }
  mTotalWidth=0;
  final int height=getHeight();
  if (mBgPadding == null) {
    mBgPadding=new Rect(0,0,0,0);
    if (getBackground() != null) {
      getBackground().getPadding(mBgPadding);
    }
    mDivider.setBounds(0,0,mDivider.getIntrinsicWidth(),mDivider.getIntrinsicHeight());
  }
  final int dividerYOffest=(height - mDivider.getMinimumHeight()) / 2;
  final int count=mSuggestions.size();
  final Rect bgPadding=mBgPadding;
  final Paint paint=mPaint;
  final int touchX=mTouchX;
  final int scrollX=getScrollX();
  final boolean scrolled=mScrolled;
  final boolean typedWordValid=mTypedWordValid;
  int x=0;
  for (int i=0; i < count; i++) {
    CharSequence suggestion=mSuggestions.get(i);
    if (suggestion == null)     continue;
    final int wordLength=suggestion.length();
    paint.setColor(mColorNormal);
    if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setColor(mColorRecommended);
    }
 else     if (i != 0 || (wordLength == 1 && count > 1)) {
      paint.setColor(mColorOther);
    }
    int wordWidth;
    if ((wordWidth=mWordWidth[i]) == 0) {
      float textWidth=paint.measureText(suggestion,0,wordLength);
      wordWidth=(int)(textWidth + mXGap * 2);
      mWordWidth[i]=wordWidth;
    }
    mWordX[i]=x;
    if (touchX != OUT_OF_BOUNDS_X_COORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) {
      if (canvas != null && !mShowingAddToDictionary) {
        canvas.translate(x,0);
        mSelectionHighlight.setBounds(0,bgPadding.top,wordWidth,height);
        mSelectionHighlight.draw(canvas);
        canvas.translate(-x,0);
      }
      mSelectedString=suggestion;
      mSelectedIndex=i;
    }
    if (canvas != null) {
      if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
        final int y=(int)(height + paint.getTextSize() - paint.descent()) / 2;
        canvas.drawText(suggestion,0,wordLength,x + wordWidth / 2,y,paint);
      }
 else {
        final int y=(int)(height - paint.getTextSize() + paint.descent()) / 2;
        float textX=x + (wordWidth / 2) - mXGap;
        float textY=y - bgPadding.bottom - bgPadding.top;
        canvas.translate(textX,textY);
        mTextPaint.setTypeface(paint.getTypeface());
        mTextPaint.setColor(paint.getColor());
        StaticLayout suggestionText=new StaticLayout(suggestion,mTextPaint,wordWidth,Alignment.ALIGN_CENTER,1.0f,0.0f,false);
        suggestionText.draw(canvas);
        canvas.translate(-textX,-textY);
      }
      paint.setColor(mColorOther);
      canvas.translate(x + wordWidth,0);
      if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) {
        canvas.translate(0,dividerYOffest);
        mDivider.draw(canvas);
        canvas.translate(0,-dividerYOffest);
      }
      canvas.translate(-x - wordWidth,0);
    }
    paint.setTypeface(Typeface.DEFAULT);
    x+=wordWidth;
  }
  mTotalWidth=x;
  if (mTargetScrollX != scrollX) {
    scrollToTarget();
  }
}