Program: 195526
Project: 195526
Buggy source:
private void drawHardwareAccelerated(Canvas canvas,Layout layout,Path highlight,Paint highlightPaint,int cursorOffsetVertical){
  final long lineRange=layout.getLineRangeForDraw(canvas);
  int firstLine=TextUtils.unpackRangeStartFromLong(lineRange);
  int lastLine=TextUtils.unpackRangeEndFromLong(lineRange);
  if (lastLine < 0)   return;
  layout.drawBackground(canvas,highlight,highlightPaint,cursorOffsetVertical,firstLine,lastLine);
  if (layout instanceof DynamicLayout) {
    if (mTextDisplayLists == null) {
      mTextDisplayLists=ArrayUtils.emptyArray(TextDisplayList.class);
    }
    DynamicLayout dynamicLayout=(DynamicLayout)layout;
    int[] blockEndLines=dynamicLayout.getBlockEndLines();
    int[] blockIndices=dynamicLayout.getBlockIndices();
    final int numberOfBlocks=dynamicLayout.getNumberOfBlocks();
    final int indexFirstChangedBlock=dynamicLayout.getIndexFirstChangedBlock();
    int endOfPreviousBlock=-1;
    int searchStartIndex=0;
    for (int i=0; i < numberOfBlocks; i++) {
      int blockEndLine=blockEndLines[i];
      int blockIndex=blockIndices[i];
      final boolean blockIsInvalid=blockIndex == DynamicLayout.INVALID_BLOCK_INDEX;
      if (blockIsInvalid) {
        blockIndex=getAvailableDisplayListIndex(blockIndices,numberOfBlocks,searchStartIndex);
        blockIndices[i]=blockIndex;
        searchStartIndex=blockIndex + 1;
      }
      if (mTextDisplayLists[blockIndex] == null) {
        mTextDisplayLists[blockIndex]=new TextDisplayList("String_Node_Str" + blockIndex);
      }
      final boolean blockDisplayListIsInvalid=mTextDisplayLists[blockIndex].needsRecord();
      RenderNode blockDisplayList=mTextDisplayLists[blockIndex].displayList;
      if (i >= indexFirstChangedBlock || blockDisplayListIsInvalid) {
        final int blockBeginLine=endOfPreviousBlock + 1;
        final int top=layout.getLineTop(blockBeginLine);
        final int bottom=layout.getLineBottom(blockEndLine);
        int left=0;
        int right=mTextView.getWidth();
        if (mTextView.getHorizontallyScrolling()) {
          float min=Float.MAX_VALUE;
          float max=Float.MIN_VALUE;
          for (int line=blockBeginLine; line <= blockEndLine; line++) {
            min=Math.min(min,layout.getLineLeft(line));
            max=Math.max(max,layout.getLineRight(line));
          }
          left=(int)min;
          right=(int)(max + 0.5f);
        }
        if (blockDisplayListIsInvalid) {
          final HardwareCanvas hardwareCanvas=blockDisplayList.start(right - left,bottom - top);
          try {
            hardwareCanvas.translate(-left,-top);
            layout.drawText(hardwareCanvas,blockBeginLine,blockEndLine);
          }
  finally {
            blockDisplayList.end(hardwareCanvas);
            blockDisplayList.setClipToBounds(false);
          }
        }
        blockDisplayList.setLeftTopRightBottom(left,top,right,bottom);
      }
      ((HardwareCanvas)canvas).drawRenderNode(blockDisplayList,0);
      endOfPreviousBlock=blockEndLine;
    }
    dynamicLayout.setIndexFirstChangedBlock(numberOfBlocks);
  }
 else {
    layout.drawText(canvas,firstLine,lastLine);
  }
}

Fixed version (ground truth):
private void drawHardwareAccelerated(Canvas canvas,Layout layout,Path highlight,Paint highlightPaint,int cursorOffsetVertical){
  final long lineRange=layout.getLineRangeForDraw(canvas);
  int firstLine=TextUtils.unpackRangeStartFromLong(lineRange);
  int lastLine=TextUtils.unpackRangeEndFromLong(lineRange);
  if (lastLine < 0)   return;
  layout.drawBackground(canvas,highlight,highlightPaint,cursorOffsetVertical,firstLine,lastLine);
  if (layout instanceof DynamicLayout) {
    if (mTextDisplayLists == null) {
      mTextDisplayLists=ArrayUtils.emptyArray(TextDisplayList.class);
    }
    DynamicLayout dynamicLayout=(DynamicLayout)layout;
    int[] blockEndLines=dynamicLayout.getBlockEndLines();
    int[] blockIndices=dynamicLayout.getBlockIndices();
    final int numberOfBlocks=dynamicLayout.getNumberOfBlocks();
    final int indexFirstChangedBlock=dynamicLayout.getIndexFirstChangedBlock();
    int endOfPreviousBlock=-1;
    int searchStartIndex=0;
    for (int i=0; i < numberOfBlocks; i++) {
      int blockEndLine=blockEndLines[i];
      int blockIndex=blockIndices[i];
      final boolean blockIsInvalid=blockIndex == DynamicLayout.INVALID_BLOCK_INDEX;
      if (blockIsInvalid) {
        blockIndex=getAvailableDisplayListIndex(blockIndices,numberOfBlocks,searchStartIndex);
        blockIndices[i]=blockIndex;
        if (mTextDisplayLists[blockIndex] != null) {
          mTextDisplayLists[blockIndex].isDirty=true;
        }
        searchStartIndex=blockIndex + 1;
      }
      if (mTextDisplayLists[blockIndex] == null) {
        mTextDisplayLists[blockIndex]=new TextDisplayList("String_Node_Str" + blockIndex);
      }
      final boolean blockDisplayListIsInvalid=mTextDisplayLists[blockIndex].needsRecord();
      RenderNode blockDisplayList=mTextDisplayLists[blockIndex].displayList;
      if (i >= indexFirstChangedBlock || blockDisplayListIsInvalid) {
        final int blockBeginLine=endOfPreviousBlock + 1;
        final int top=layout.getLineTop(blockBeginLine);
        final int bottom=layout.getLineBottom(blockEndLine);
        int left=0;
        int right=mTextView.getWidth();
        if (mTextView.getHorizontallyScrolling()) {
          float min=Float.MAX_VALUE;
          float max=Float.MIN_VALUE;
          for (int line=blockBeginLine; line <= blockEndLine; line++) {
            min=Math.min(min,layout.getLineLeft(line));
            max=Math.max(max,layout.getLineRight(line));
          }
          left=(int)min;
          right=(int)(max + 0.5f);
        }
        if (blockDisplayListIsInvalid) {
          final HardwareCanvas hardwareCanvas=blockDisplayList.start(right - left,bottom - top);
          try {
            hardwareCanvas.translate(-left,-top);
            layout.drawText(hardwareCanvas,blockBeginLine,blockEndLine);
            mTextDisplayLists[blockIndex].isDirty=false;
          }
  finally {
            blockDisplayList.end(hardwareCanvas);
            blockDisplayList.setClipToBounds(false);
          }
        }
        blockDisplayList.setLeftTopRightBottom(left,top,right,bottom);
      }
      ((HardwareCanvas)canvas).drawRenderNode(blockDisplayList,0);
      endOfPreviousBlock=blockEndLine;
    }
    dynamicLayout.setIndexFirstChangedBlock(numberOfBlocks);
  }
 else {
    layout.drawText(canvas,firstLine,lastLine);
  }
}