Program: 88349
Project: 88349
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;
  if (mSuggestions == null)   return;
  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());
  }
  int x=0;
  final int count=mSuggestions.size();
  final int width=getWidth();
  final Rect bgPadding=mBgPadding;
  final Paint paint=mPaint;
  final int touchX=mTouchX;
  final int scrollX=getScrollX();
  final boolean scrolled=mScrolled;
  final boolean typedWordValid=mTypedWordValid;
  final int y=(int)(height + mPaint.getTextSize() - mDescent) / 2;
  for (int i=0; i < count; i++) {
    CharSequence suggestion=mSuggestions.get(i);
    if (suggestion == null)     continue;
    paint.setColor(mColorNormal);
    if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setColor(mColorRecommended);
    }
 else     if (i != 0) {
      paint.setColor(mColorOther);
    }
    final int wordWidth;
    if (mWordWidth[i] != 0) {
      wordWidth=mWordWidth[i];
    }
 else {
      float textWidth=paint.measureText(suggestion,0,suggestion.length());
      wordWidth=Math.max(mMinTouchableWidth,(int)textWidth + X_GAP * 2);
      mWordWidth[i]=wordWidth;
    }
    mWordX[i]=x;
    if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled && touchX != OUT_OF_BOUNDS) {
      if (canvas != null && !mShowingAddToDictionary) {
        canvas.translate(x,0);
        mSelectionHighlight.setBounds(0,bgPadding.top,wordWidth,height);
        mSelectionHighlight.draw(canvas);
        canvas.translate(-x,0);
        showPreview(i,null);
      }
      mSelectedString=suggestion;
      mSelectedIndex=i;
    }
    if (canvas != null) {
      canvas.drawText(suggestion,0,suggestion.length(),x + wordWidth / 2,y,paint);
      paint.setColor(mColorOther);
      canvas.translate(x + wordWidth,0);
      if (!(mShowingAddToDictionary && i == 1)) {
        mDivider.draw(canvas);
      }
      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;
  if (mSuggestions == null)   return;
  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());
  }
  int x=0;
  final int count=Math.min(mSuggestions.size(),MAX_SUGGESTIONS);
  final int width=getWidth();
  final Rect bgPadding=mBgPadding;
  final Paint paint=mPaint;
  final int touchX=mTouchX;
  final int scrollX=getScrollX();
  final boolean scrolled=mScrolled;
  final boolean typedWordValid=mTypedWordValid;
  final int y=(int)(height + mPaint.getTextSize() - mDescent) / 2;
  for (int i=0; i < count; i++) {
    CharSequence suggestion=mSuggestions.get(i);
    if (suggestion == null)     continue;
    paint.setColor(mColorNormal);
    if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setColor(mColorRecommended);
    }
 else     if (i != 0) {
      paint.setColor(mColorOther);
    }
    final int wordWidth;
    if (mWordWidth[i] != 0) {
      wordWidth=mWordWidth[i];
    }
 else {
      float textWidth=paint.measureText(suggestion,0,suggestion.length());
      wordWidth=Math.max(mMinTouchableWidth,(int)textWidth + X_GAP * 2);
      mWordWidth[i]=wordWidth;
    }
    mWordX[i]=x;
    if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled && touchX != OUT_OF_BOUNDS) {
      if (canvas != null && !mShowingAddToDictionary) {
        canvas.translate(x,0);
        mSelectionHighlight.setBounds(0,bgPadding.top,wordWidth,height);
        mSelectionHighlight.draw(canvas);
        canvas.translate(-x,0);
        showPreview(i,null);
      }
      mSelectedString=suggestion;
      mSelectedIndex=i;
    }
    if (canvas != null) {
      canvas.drawText(suggestion,0,suggestion.length(),x + wordWidth / 2,y,paint);
      paint.setColor(mColorOther);
      canvas.translate(x + wordWidth,0);
      if (!(mShowingAddToDictionary && i == 1)) {
        mDivider.draw(canvas);
      }
      canvas.translate(-x - wordWidth,0);
    }
    paint.setTypeface(Typeface.DEFAULT);
    x+=wordWidth;
  }
  mTotalWidth=x;
  if (mTargetScrollX != scrollX) {
    scrollToTarget();
  }
}