Program: 14809
Project: 14809
Buggy source:
private boolean addMedia(Uri imageUri,SpannableStringBuilder ssb){
  if (ssb != null && !MediaUtils.isInMediaStore(imageUri))   imageUri=MediaUtils.downloadExternalMedia(getActivity(),imageUri);
  if (imageUri == null) {
    return false;
  }
  Bitmap thumbnailBitmap;
  String mediaTitle;
  if (imageUri.toString().contains("String_Node_Str") && !MediaUtils.isInMediaStore(imageUri)) {
    thumbnailBitmap=BitmapFactory.decodeResource(getActivity().getResources(),R.drawable.media_movieclip);
    mediaTitle=getResources().getString(R.string.video);
  }
 else {
    ImageHelper ih=new ImageHelper();
    thumbnailBitmap=ih.getThumbnailForWPImageSpan(getActivity(),imageUri.getEncodedPath());
    if (thumbnailBitmap == null)     return false;
    mediaTitle=ih.getTitleForWPImageSpan(getActivity(),imageUri.getEncodedPath());
  }
  WPImageSpan is=new WPImageSpan(getActivity(),thumbnailBitmap,imageUri);
  MediaFile mediaFile=is.getMediaFile();
  mediaFile.setPostID(mActivity.getPost().getId());
  mediaFile.setTitle(mediaTitle);
  mediaFile.setFilePath(is.getImageSource().toString());
  MediaUtils.setWPImageSpanWidth(getActivity(),imageUri,is);
  if (imageUri.getEncodedPath() != null)   mediaFile.setVideo(imageUri.getEncodedPath().contains("String_Node_Str"));
  mediaFile.save();
  if (ssb != null) {
    ssb.append("String_Node_Str");
    ssb.setSpan(is,ssb.length() - 1,ssb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    AlignmentSpan.Standard as=new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
    ssb.setSpan(as,ssb.length() - 1,ssb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append("String_Node_Str");
  }
 else {
    int selectionStart=mContentEditText.getSelectionStart();
    mStyleStart=selectionStart;
    int selectionEnd=mContentEditText.getSelectionEnd();
    if (selectionStart > selectionEnd) {
      int temp=selectionEnd;
      selectionEnd=selectionStart;
      selectionStart=temp;
    }
    Editable s=mContentEditText.getText();
    if (s == null)     return false;
    int line, column=0;
    if (mContentEditText.getLayout() != null) {
      line=mContentEditText.getLayout().getLineForOffset(selectionStart);
      column=mContentEditText.getSelectionStart() - mContentEditText.getLayout().getLineStart(line);
    }
    WPImageSpan[] image_spans=s.getSpans(selectionStart,selectionEnd,WPImageSpan.class);
    if (image_spans.length != 0) {
      s.insert(selectionEnd,"String_Node_Str");
      selectionStart=selectionStart + 2;
      selectionEnd=selectionEnd + 2;
    }
 else     if (column != 0) {
      s.insert(selectionEnd,"String_Node_Str");
      selectionStart=selectionStart + 1;
      selectionEnd=selectionEnd + 1;
    }
    s.insert(selectionStart,"String_Node_Str");
    s.setSpan(is,selectionStart,selectionEnd + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    AlignmentSpan.Standard as=new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
    s.setSpan(as,selectionStart,selectionEnd + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    s.insert(selectionEnd + 1,"String_Node_Str");
  }
  if (mActivity != null && !mActivity.getSupportActionBar().isShowing())   ((InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
  return true;
}

Fixed version (ground truth):
private boolean addMedia(Uri imageUri,SpannableStringBuilder ssb){
  if (ssb != null && !MediaUtils.isInMediaStore(imageUri))   imageUri=MediaUtils.downloadExternalMedia(getActivity(),imageUri);
  if (imageUri == null) {
    return false;
  }
  Bitmap thumbnailBitmap;
  String mediaTitle;
  if (imageUri.toString().contains("String_Node_Str") && !MediaUtils.isInMediaStore(imageUri)) {
    thumbnailBitmap=BitmapFactory.decodeResource(getActivity().getResources(),R.drawable.media_movieclip);
    mediaTitle=getResources().getString(R.string.video);
  }
 else {
    ImageHelper ih=new ImageHelper();
    thumbnailBitmap=ih.getThumbnailForWPImageSpan(getActivity(),imageUri.getEncodedPath());
    if (thumbnailBitmap == null)     return false;
    mediaTitle=ih.getTitleForWPImageSpan(getActivity(),imageUri.getEncodedPath());
  }
  WPImageSpan is=new WPImageSpan(getActivity(),thumbnailBitmap,imageUri);
  MediaFile mediaFile=is.getMediaFile();
  mediaFile.setPostID(mActivity.getPost().getLocalTablePostId());
  mediaFile.setTitle(mediaTitle);
  mediaFile.setFilePath(is.getImageSource().toString());
  MediaUtils.setWPImageSpanWidth(getActivity(),imageUri,is);
  if (imageUri.getEncodedPath() != null)   mediaFile.setVideo(imageUri.getEncodedPath().contains("String_Node_Str"));
  mediaFile.save();
  if (ssb != null) {
    ssb.append("String_Node_Str");
    ssb.setSpan(is,ssb.length() - 1,ssb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    AlignmentSpan.Standard as=new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
    ssb.setSpan(as,ssb.length() - 1,ssb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append("String_Node_Str");
  }
 else {
    int selectionStart=mContentEditText.getSelectionStart();
    mStyleStart=selectionStart;
    int selectionEnd=mContentEditText.getSelectionEnd();
    if (selectionStart > selectionEnd) {
      int temp=selectionEnd;
      selectionEnd=selectionStart;
      selectionStart=temp;
    }
    Editable s=mContentEditText.getText();
    if (s == null)     return false;
    int line, column=0;
    if (mContentEditText.getLayout() != null) {
      line=mContentEditText.getLayout().getLineForOffset(selectionStart);
      column=mContentEditText.getSelectionStart() - mContentEditText.getLayout().getLineStart(line);
    }
    WPImageSpan[] image_spans=s.getSpans(selectionStart,selectionEnd,WPImageSpan.class);
    if (image_spans.length != 0) {
      s.insert(selectionEnd,"String_Node_Str");
      selectionStart=selectionStart + 2;
      selectionEnd=selectionEnd + 2;
    }
 else     if (column != 0) {
      s.insert(selectionEnd,"String_Node_Str");
      selectionStart=selectionStart + 1;
      selectionEnd=selectionEnd + 1;
    }
    s.insert(selectionStart,"String_Node_Str");
    s.setSpan(is,selectionStart,selectionEnd + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    AlignmentSpan.Standard as=new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
    s.setSpan(as,selectionStart,selectionEnd + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    s.insert(selectionEnd + 1,"String_Node_Str");
  }
  if (mActivity != null && !mActivity.getSupportActionBar().isShowing())   ((InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
  return true;
}