Program: 157534
Project: 157534
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 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);
    }
    final int y=(int)(height - mPaint.getTextSize() - mDescent) / 2;
    int wordWidth;
    if ((wordWidth=mWordWidth[i]) == 0) {
      float textWidth=paint.measureText(suggestion,0,wordLength);
      wordWidth=Math.max(mMinTouchableWidth,(int)textWidth + X_GAP * 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) {
      int textX=x - bgPadding.left - bgPadding.right + (wordWidth / 2);
      int textY=y - bgPadding.bottom - bgPadding.top;
      canvas.translate(textX,textY);
      TextPaint suggestionPaint=new TextPaint(paint);
      StaticLayout suggestionText=new StaticLayout(suggestion,suggestionPaint,wordWidth,Alignment.ALIGN_NORMAL,1.0f,1.0f,false);
      suggestionText.draw(canvas);
      canvas.translate(-textX,-textY);
      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;
  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 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);
    }
    final int y=(int)(height - mPaint.getTextSize() - mDescent) / 2;
    int wordWidth;
    if ((wordWidth=mWordWidth[i]) == 0) {
      float textWidth=paint.measureText(suggestion,0,wordLength);
      wordWidth=Math.max(mMinTouchableWidth,(int)textWidth + X_GAP * 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) {
      float textX=x - bgPadding.left - bgPadding.right + (wordWidth / 2);
      float textY=y - bgPadding.bottom - bgPadding.top;
      canvas.translate(textX,textY);
      TextPaint suggestionPaint=new TextPaint(paint);
      StaticLayout suggestionText=new StaticLayout(suggestion,suggestionPaint,wordWidth,Alignment.ALIGN_NORMAL,1.0f,1.0f,false);
      suggestionText.draw(canvas);
      canvas.translate(-textX,-textY);
      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();
  }
}