Program: 32151
Project: 32151
Buggy source:
/** 
 * Highlight the pattern in the text.
 * @param textView the textView in which the text is displayed.
 * @param text the text to display.
 * @param pattern the pattern to highlight.
 */
protected void highlightPattern(TextView textView,Spannable text,String htmlFormattedText,String pattern){
  if (null == textView) {
    return;
  }
  if (!TextUtils.isEmpty(pattern) && !TextUtils.isEmpty(text) && (text.length() >= pattern.length())) {
    String lowerText=text.toString().toLowerCase();
    String lowerPattern=pattern.toLowerCase();
    int start=0;
    int pos=lowerText.indexOf(lowerPattern,start);
    while (pos >= 0) {
      start=pos + lowerPattern.length();
      text.setSpan(getHighLightTextStyle(),pos,start,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      text.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),pos,start,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      pos=lowerText.indexOf(lowerPattern,start);
    }
  }
  final ConsoleHtmlTagHandler htmlTagHandler=new ConsoleHtmlTagHandler();
  htmlTagHandler.mContext=mContext;
  CharSequence sequence=null;
  if (null != htmlFormattedText) {
    boolean isCustomizable=htmlFormattedText.indexOf("String_Node_Str") < 0;
    sequence=Html.fromHtml(htmlFormattedText.replace("String_Node_Str","String_Node_Str"),null,isCustomizable ? htmlTagHandler : null);
    if (!TextUtils.isEmpty(sequence)) {
      int markStart=0;
      int markEnd=sequence.length() - 1;
      for (; (markStart < sequence.length() - 1) && ('\n' == sequence.charAt(markStart)); markStart++)       ;
      for (; (markEnd >= 0) && ('\n' == sequence.charAt(markEnd)); markEnd--)       ;
      if (markEnd < markStart) {
        sequence=sequence.subSequence(0,0);
      }
 else {
        sequence=sequence.subSequence(markStart,markEnd);
      }
    }
  }
 else {
    sequence=text;
  }
  SpannableStringBuilder strBuilder=new SpannableStringBuilder(sequence);
  URLSpan[] urls=strBuilder.getSpans(0,text.length(),URLSpan.class);
  if ((null != urls) && (urls.length > 0)) {
    for (    URLSpan span : urls) {
      makeLinkClickable(strBuilder,span);
    }
  }
  textView.setText(strBuilder);
  if (null != mLinkMovementMethod) {
    textView.setMovementMethod(mLinkMovementMethod);
  }
}

Fixed version (ground truth):
/** 
 * Highlight the pattern in the text.
 * @param textView the textView in which the text is displayed.
 * @param text the text to display.
 * @param pattern the pattern to highlight.
 */
protected void highlightPattern(TextView textView,Spannable text,String htmlFormattedText,String pattern){
  if (null == textView) {
    return;
  }
  if (!TextUtils.isEmpty(pattern) && !TextUtils.isEmpty(text) && (text.length() >= pattern.length())) {
    String lowerText=text.toString().toLowerCase();
    String lowerPattern=pattern.toLowerCase();
    int start=0;
    int pos=lowerText.indexOf(lowerPattern,start);
    while (pos >= 0) {
      start=pos + lowerPattern.length();
      text.setSpan(getHighLightTextStyle(),pos,start,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      text.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),pos,start,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      pos=lowerText.indexOf(lowerPattern,start);
    }
  }
  final ConsoleHtmlTagHandler htmlTagHandler=new ConsoleHtmlTagHandler();
  htmlTagHandler.mContext=mContext;
  CharSequence sequence=null;
  if (null != htmlFormattedText) {
    boolean isCustomizable=htmlFormattedText.indexOf("String_Node_Str") < 0;
    sequence=Html.fromHtml(htmlFormattedText.replace("String_Node_Str","String_Node_Str"),null,isCustomizable ? htmlTagHandler : null);
    if (!TextUtils.isEmpty(sequence)) {
      int markStart=0;
      int markEnd=sequence.length() - 1;
      for (; (markStart < sequence.length() - 1) && ('\n' == sequence.charAt(markStart)); markStart++)       ;
      for (; (markEnd >= 0) && ('\n' == sequence.charAt(markEnd)); markEnd--)       ;
      if (markEnd < markStart) {
        sequence=sequence.subSequence(0,0);
      }
 else {
        sequence=sequence.subSequence(markStart,markEnd + 1);
      }
    }
  }
 else {
    sequence=text;
  }
  SpannableStringBuilder strBuilder=new SpannableStringBuilder(sequence);
  URLSpan[] urls=strBuilder.getSpans(0,text.length(),URLSpan.class);
  if ((null != urls) && (urls.length > 0)) {
    for (    URLSpan span : urls) {
      makeLinkClickable(strBuilder,span);
    }
  }
  textView.setText(strBuilder);
  if (null != mLinkMovementMethod) {
    textView.setMovementMethod(mLinkMovementMethod);
  }
}