Program: 32154
Project: 32154
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;
  SpannableStringBuilder strBuilder=new SpannableStringBuilder(text);
  URLSpan[] urls=strBuilder.getSpans(0,text.length(),URLSpan.class);
  if ((null != urls) && (urls.length > 0)) {
    for (    URLSpan span : urls) {
      makeLinkClickable(strBuilder,span);
    }
    if (null != htmlFormattedText) {
      textView.setText(Html.fromHtml(htmlFormattedText,null,htmlTagHandler));
    }
 else {
      textView.setText(text);
    }
    textView.setMovementMethod(LinkMovementMethod.getInstance());
  }
 else {
    if (null != htmlFormattedText) {
      textView.setText(Html.fromHtml(htmlFormattedText,null,htmlTagHandler));
    }
 else {
      textView.setText(text);
    }
  }
}

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;
  SpannableStringBuilder strBuilder=new SpannableStringBuilder(text);
  URLSpan[] urls=strBuilder.getSpans(0,text.length(),URLSpan.class);
  if ((null != urls) && (urls.length > 0)) {
    for (    URLSpan span : urls) {
      makeLinkClickable(strBuilder,span);
    }
    if (null != htmlFormattedText) {
      textView.setText(Html.fromHtml(htmlFormattedText.replace("String_Node_Str","String_Node_Str"),null,htmlTagHandler));
    }
 else {
      textView.setText(text);
    }
    textView.setMovementMethod(LinkMovementMethod.getInstance());
  }
 else {
    if (null != htmlFormattedText) {
      textView.setText(Html.fromHtml(htmlFormattedText.replace("String_Node_Str","String_Node_Str"),null,htmlTagHandler));
    }
 else {
      textView.setText(text);
    }
  }
}