Program: 1951
Project: 1951
Buggy source:
@Override protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec){
  int widthMode=MeasureSpec.getMode(widthMeasureSpec);
  int heightMode=MeasureSpec.getMode(heightMeasureSpec);
  int widthSize=MeasureSpec.getSize(widthMeasureSpec);
  int heightSize=MeasureSpec.getSize(heightMeasureSpec);
  int width;
  int height;
  BoringLayout.Metrics boring=UNKNOWN_BORING;
  BoringLayout.Metrics hintBoring=UNKNOWN_BORING;
  if (mTextDir == null) {
    getTextDirectionHeuristic();
  }
  int des=-1;
  boolean fromexisting=false;
  if (widthMode == MeasureSpec.EXACTLY) {
    width=widthSize;
  }
 else {
    if (mLayout != null && mEllipsize == null) {
      des=desired(mLayout);
    }
    if (des < 0) {
      boring=BoringLayout.isBoring(mTransformed,mTextPaint,mTextDir,mBoring);
      if (boring != null) {
        mBoring=boring;
      }
    }
 else {
      fromexisting=true;
    }
    if (boring == null || boring == UNKNOWN_BORING) {
      if (des < 0) {
        des=(int)FloatMath.ceil(Layout.getDesiredWidth(mTransformed,mTextPaint));
      }
      width=des;
    }
 else {
      width=boring.width;
    }
    final Drawables dr=mDrawables;
    if (dr != null) {
      width=Math.max(width,dr.mDrawableWidthTop);
      width=Math.max(width,dr.mDrawableWidthBottom);
    }
    if (mHint != null) {
      int hintDes=-1;
      int hintWidth;
      if (mHintLayout != null && mEllipsize == null) {
        hintDes=desired(mHintLayout);
      }
      if (hintDes < 0) {
        hintBoring=BoringLayout.isBoring(mHint,mTextPaint,mTextDir,mHintBoring);
        if (hintBoring != null) {
          mHintBoring=hintBoring;
        }
      }
      if (hintBoring == null || hintBoring == UNKNOWN_BORING) {
        if (hintDes < 0) {
          hintDes=(int)FloatMath.ceil(Layout.getDesiredWidth(mHint,mTextPaint));
        }
        hintWidth=hintDes;
      }
 else {
        hintWidth=hintBoring.width;
      }
      if (hintWidth > width) {
        width=hintWidth;
      }
    }
    width+=getCompoundPaddingLeft() + getCompoundPaddingRight();
    if (mMaxWidthMode == EMS) {
      width=Math.min(width,mMaxWidth * getLineHeight());
    }
 else {
      width=Math.min(width,mMaxWidth);
    }
    if (mMinWidthMode == EMS) {
      width=Math.max(width,mMinWidth * getLineHeight());
    }
 else {
      width=Math.max(width,mMinWidth);
    }
    width=Math.max(width,getSuggestedMinimumWidth());
    if (widthMode == MeasureSpec.AT_MOST) {
      width=Math.min(widthSize,width);
    }
  }
  int want=width - getCompoundPaddingLeft() - getCompoundPaddingRight();
  int unpaddedWidth=want;
  if (mHorizontallyScrolling)   want=VERY_WIDE;
  int hintWant=want;
  int hintWidth=(mHintLayout == null) ? hintWant : mHintLayout.getWidth();
  if (mLayout == null) {
    makeNewLayout(want,hintWant,boring,hintBoring,width - getCompoundPaddingLeft() - getCompoundPaddingRight(),false);
  }
 else {
    final boolean layoutChanged=(mLayout.getWidth() != want) || (hintWidth != hintWant) || (mLayout.getEllipsizedWidth() != width - getCompoundPaddingLeft() - getCompoundPaddingRight());
    final boolean widthChanged=(mHint == null) && (mEllipsize == null) && (want > mLayout.getWidth())&& (mLayout instanceof BoringLayout || (fromexisting && des >= 0 && des <= want));
    final boolean maximumChanged=(mMaxMode != mOldMaxMode) || (mMaximum != mOldMaximum);
    if (layoutChanged || maximumChanged) {
      if (!maximumChanged && widthChanged) {
        mLayout.increaseWidthTo(want);
      }
 else {
        makeNewLayout(want,hintWant,boring,hintBoring,width - getCompoundPaddingLeft() - getCompoundPaddingRight(),false);
      }
    }
 else {
    }
  }
  if (heightMode == MeasureSpec.EXACTLY) {
    height=heightSize;
    mDesiredHeightAtMeasure=-1;
  }
 else {
    int desired=getDesiredHeight();
    height=desired;
    mDesiredHeightAtMeasure=desired;
    if (heightMode == MeasureSpec.AT_MOST) {
      height=Math.min(desired,heightSize);
    }
  }
  int unpaddedHeight=height - getCompoundPaddingTop() - getCompoundPaddingBottom();
  if (mMaxMode == LINES && mLayout.getLineCount() > mMaximum) {
    unpaddedHeight=Math.min(unpaddedHeight,mLayout.getLineTop(mMaximum));
  }
  if (mMovement != null || mLayout.getWidth() > unpaddedWidth || mLayout.getHeight() > unpaddedHeight) {
    registerForPreDraw();
  }
 else {
    scrollTo(0,0);
  }
  setMeasuredDimension(width,height);
}

Fixed version (ground truth):
@Override protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec){
  int widthMode=MeasureSpec.getMode(widthMeasureSpec);
  int heightMode=MeasureSpec.getMode(heightMeasureSpec);
  int widthSize=MeasureSpec.getSize(widthMeasureSpec);
  int heightSize=MeasureSpec.getSize(heightMeasureSpec);
  int width;
  int height;
  BoringLayout.Metrics boring=UNKNOWN_BORING;
  BoringLayout.Metrics hintBoring=UNKNOWN_BORING;
  if (mTextDir == null) {
    mTextDir=getTextDirectionHeuristic();
  }
  int des=-1;
  boolean fromexisting=false;
  if (widthMode == MeasureSpec.EXACTLY) {
    width=widthSize;
  }
 else {
    if (mLayout != null && mEllipsize == null) {
      des=desired(mLayout);
    }
    if (des < 0) {
      boring=BoringLayout.isBoring(mTransformed,mTextPaint,mTextDir,mBoring);
      if (boring != null) {
        mBoring=boring;
      }
    }
 else {
      fromexisting=true;
    }
    if (boring == null || boring == UNKNOWN_BORING) {
      if (des < 0) {
        des=(int)FloatMath.ceil(Layout.getDesiredWidth(mTransformed,mTextPaint));
      }
      width=des;
    }
 else {
      width=boring.width;
    }
    final Drawables dr=mDrawables;
    if (dr != null) {
      width=Math.max(width,dr.mDrawableWidthTop);
      width=Math.max(width,dr.mDrawableWidthBottom);
    }
    if (mHint != null) {
      int hintDes=-1;
      int hintWidth;
      if (mHintLayout != null && mEllipsize == null) {
        hintDes=desired(mHintLayout);
      }
      if (hintDes < 0) {
        hintBoring=BoringLayout.isBoring(mHint,mTextPaint,mTextDir,mHintBoring);
        if (hintBoring != null) {
          mHintBoring=hintBoring;
        }
      }
      if (hintBoring == null || hintBoring == UNKNOWN_BORING) {
        if (hintDes < 0) {
          hintDes=(int)FloatMath.ceil(Layout.getDesiredWidth(mHint,mTextPaint));
        }
        hintWidth=hintDes;
      }
 else {
        hintWidth=hintBoring.width;
      }
      if (hintWidth > width) {
        width=hintWidth;
      }
    }
    width+=getCompoundPaddingLeft() + getCompoundPaddingRight();
    if (mMaxWidthMode == EMS) {
      width=Math.min(width,mMaxWidth * getLineHeight());
    }
 else {
      width=Math.min(width,mMaxWidth);
    }
    if (mMinWidthMode == EMS) {
      width=Math.max(width,mMinWidth * getLineHeight());
    }
 else {
      width=Math.max(width,mMinWidth);
    }
    width=Math.max(width,getSuggestedMinimumWidth());
    if (widthMode == MeasureSpec.AT_MOST) {
      width=Math.min(widthSize,width);
    }
  }
  int want=width - getCompoundPaddingLeft() - getCompoundPaddingRight();
  int unpaddedWidth=want;
  if (mHorizontallyScrolling)   want=VERY_WIDE;
  int hintWant=want;
  int hintWidth=(mHintLayout == null) ? hintWant : mHintLayout.getWidth();
  if (mLayout == null) {
    makeNewLayout(want,hintWant,boring,hintBoring,width - getCompoundPaddingLeft() - getCompoundPaddingRight(),false);
  }
 else {
    final boolean layoutChanged=(mLayout.getWidth() != want) || (hintWidth != hintWant) || (mLayout.getEllipsizedWidth() != width - getCompoundPaddingLeft() - getCompoundPaddingRight());
    final boolean widthChanged=(mHint == null) && (mEllipsize == null) && (want > mLayout.getWidth())&& (mLayout instanceof BoringLayout || (fromexisting && des >= 0 && des <= want));
    final boolean maximumChanged=(mMaxMode != mOldMaxMode) || (mMaximum != mOldMaximum);
    if (layoutChanged || maximumChanged) {
      if (!maximumChanged && widthChanged) {
        mLayout.increaseWidthTo(want);
      }
 else {
        makeNewLayout(want,hintWant,boring,hintBoring,width - getCompoundPaddingLeft() - getCompoundPaddingRight(),false);
      }
    }
 else {
    }
  }
  if (heightMode == MeasureSpec.EXACTLY) {
    height=heightSize;
    mDesiredHeightAtMeasure=-1;
  }
 else {
    int desired=getDesiredHeight();
    height=desired;
    mDesiredHeightAtMeasure=desired;
    if (heightMode == MeasureSpec.AT_MOST) {
      height=Math.min(desired,heightSize);
    }
  }
  int unpaddedHeight=height - getCompoundPaddingTop() - getCompoundPaddingBottom();
  if (mMaxMode == LINES && mLayout.getLineCount() > mMaximum) {
    unpaddedHeight=Math.min(unpaddedHeight,mLayout.getLineTop(mMaximum));
  }
  if (mMovement != null || mLayout.getWidth() > unpaddedWidth || mLayout.getHeight() > unpaddedHeight) {
    registerForPreDraw();
  }
 else {
    scrollTo(0,0);
  }
  setMeasuredDimension(width,height);
}