Program: 43520
Project: 43520
Buggy source:
private void replaceText(CharSequence text,int newCursorPosition,boolean composing){
  final Editable content=getEditable();
  if (content == null) {
    return;
  }
  beginBatchEdit();
  int a=getComposingSpanStart(content);
  int b=getComposingSpanEnd(content);
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + a + "String_Node_Str"+ b);
  if (b < a) {
    int tmp=a;
    a=b;
    b=tmp;
  }
  if (a != -1 && b != -1) {
    removeComposingSpans(content);
  }
 else {
    a=Selection.getSelectionStart(content);
    b=Selection.getSelectionEnd(content);
    if (a >= 0 && b >= 0 && a != b) {
      if (b < a) {
        int tmp=a;
        a=b;
        b=tmp;
      }
    }
  }
  if (composing) {
    Spannable sp=null;
    if (!(text instanceof Spannable)) {
      sp=new SpannableStringBuilder(text);
      text=sp;
      if (mDefaultComposingSpans == null) {
        Context context;
        if (mTargetView != null) {
          context=mTargetView.getContext();
        }
 else         if (mIMM.mServedView != null) {
          context=mIMM.mServedView.getContext();
        }
 else {
          context=null;
        }
        if (context != null) {
          TypedArray ta=context.getTheme().obtainStyledAttributes(new int[]{com.android.internal.R.attr.candidatesTextStyleSpans});
          CharSequence style=ta.getText(0);
          ta.recycle();
          if (style != null && style instanceof Spanned) {
            mDefaultComposingSpans=((Spanned)style).getSpans(0,style.length(),Object.class);
          }
        }
      }
      if (mDefaultComposingSpans != null) {
        for (int i=0; i < mDefaultComposingSpans.length; ++i) {
          sp.setSpan(mDefaultComposingSpans[i],0,sp.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
      }
    }
 else {
      sp=(Spannable)text;
    }
    setComposingSpans(sp);
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + a + "String_Node_Str"+ b+ "String_Node_Str"+ text+ "String_Node_Str"+ composing+ "String_Node_Str"+ text.getClass().getCanonicalName());
  if (DEBUG) {
    LogPrinter lp=new LogPrinter(Log.VERBOSE,TAG);
    lp.println("String_Node_Str");
    TextUtils.dumpSpans(content,lp,"String_Node_Str");
    lp.println("String_Node_Str");
    TextUtils.dumpSpans(text,lp,"String_Node_Str");
  }
  if (newCursorPosition > 0) {
    newCursorPosition+=b - 1;
  }
 else {
    newCursorPosition+=a;
  }
  if (newCursorPosition < 0)   newCursorPosition=0;
  if (newCursorPosition > content.length())   newCursorPosition=content.length();
  Selection.setSelection(content,newCursorPosition);
  content.replace(a,b,text);
  if (DEBUG) {
    LogPrinter lp=new LogPrinter(Log.VERBOSE,TAG);
    lp.println("String_Node_Str");
    TextUtils.dumpSpans(content,lp,"String_Node_Str");
  }
  endBatchEdit();
}

Fixed version (ground truth):
private void replaceText(CharSequence text,int newCursorPosition,boolean composing){
  final Editable content=getEditable();
  if (content == null) {
    return;
  }
  beginBatchEdit();
  int a=getComposingSpanStart(content);
  int b=getComposingSpanEnd(content);
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + a + "String_Node_Str"+ b);
  if (b < a) {
    int tmp=a;
    a=b;
    b=tmp;
  }
  if (a != -1 && b != -1) {
    removeComposingSpans(content);
  }
 else {
    a=Selection.getSelectionStart(content);
    b=Selection.getSelectionEnd(content);
    if (a < 0)     a=0;
    if (b < 0)     b=0;
    if (b < a) {
      int tmp=a;
      a=b;
      b=tmp;
    }
  }
  if (composing) {
    Spannable sp=null;
    if (!(text instanceof Spannable)) {
      sp=new SpannableStringBuilder(text);
      text=sp;
      if (mDefaultComposingSpans == null) {
        Context context;
        if (mTargetView != null) {
          context=mTargetView.getContext();
        }
 else         if (mIMM.mServedView != null) {
          context=mIMM.mServedView.getContext();
        }
 else {
          context=null;
        }
        if (context != null) {
          TypedArray ta=context.getTheme().obtainStyledAttributes(new int[]{com.android.internal.R.attr.candidatesTextStyleSpans});
          CharSequence style=ta.getText(0);
          ta.recycle();
          if (style != null && style instanceof Spanned) {
            mDefaultComposingSpans=((Spanned)style).getSpans(0,style.length(),Object.class);
          }
        }
      }
      if (mDefaultComposingSpans != null) {
        for (int i=0; i < mDefaultComposingSpans.length; ++i) {
          sp.setSpan(mDefaultComposingSpans[i],0,sp.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
      }
    }
 else {
      sp=(Spannable)text;
    }
    setComposingSpans(sp);
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + a + "String_Node_Str"+ b+ "String_Node_Str"+ text+ "String_Node_Str"+ composing+ "String_Node_Str"+ text.getClass().getCanonicalName());
  if (DEBUG) {
    LogPrinter lp=new LogPrinter(Log.VERBOSE,TAG);
    lp.println("String_Node_Str");
    TextUtils.dumpSpans(content,lp,"String_Node_Str");
    lp.println("String_Node_Str");
    TextUtils.dumpSpans(text,lp,"String_Node_Str");
  }
  if (newCursorPosition > 0) {
    newCursorPosition+=b - 1;
  }
 else {
    newCursorPosition+=a;
  }
  if (newCursorPosition < 0)   newCursorPosition=0;
  if (newCursorPosition > content.length())   newCursorPosition=content.length();
  Selection.setSelection(content,newCursorPosition);
  content.replace(a,b,text);
  if (DEBUG) {
    LogPrinter lp=new LogPrinter(Log.VERBOSE,TAG);
    lp.println("String_Node_Str");
    TextUtils.dumpSpans(content,lp,"String_Node_Str");
  }
  endBatchEdit();
}