Program: 15190
Project: 15190
Buggy source:
private void addMedia(String imgPath,Uri curStream){
  Bitmap resizedBitmap=null;
  ImageHelper ih=new ImageHelper();
  Display display=getWindowManager().getDefaultDisplay();
  int width=display.getWidth();
  HashMap<String,Object> mediaData=ih.getImageBytesForPath(imgPath,EditPost.this);
  if (mediaData == null) {
    Toast.makeText(EditPost.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
    return;
  }
  BitmapFactory.Options opts=new BitmapFactory.Options();
  opts.inJustDecodeBounds=true;
  byte[] bytes=(byte[])mediaData.get("String_Node_Str");
  BitmapFactory.decodeByteArray(bytes,0,bytes.length,opts);
  float conversionFactor=0.25f;
  if (opts.outWidth > opts.outHeight)   conversionFactor=0.45f;
  byte[] finalBytes=ih.createThumbnail(bytes,String.valueOf((int)(width * conversionFactor)),(String)mediaData.get("String_Node_Str"),true);
  resizedBitmap=BitmapFactory.decodeByteArray(finalBytes,0,finalBytes.length);
  WPEditText content=(WPEditText)findViewById(R.id.postContent);
  int selectionStart=content.getSelectionStart();
  styleStart=selectionStart;
  int selectionEnd=content.getSelectionEnd();
  if (selectionStart > selectionEnd) {
    int temp=selectionEnd;
    selectionEnd=selectionStart;
    selectionStart=temp;
  }
  if (content.getText().length() == 0) {
    content.setText("String_Node_Str");
  }
  Editable s=content.getText();
  WPImageSpan is=new WPImageSpan(EditPost.this,resizedBitmap,curStream);
  String imageWidth=WordPress.currentBlog.getMaxImageWidth();
  if (!imageWidth.equals("String_Node_Str")) {
    try {
      is.setWidth(Integer.valueOf(imageWidth));
    }
 catch (    NumberFormatException e) {
      e.printStackTrace();
    }
  }
  is.setTitle((String)mediaData.get("String_Node_Str"));
  is.setImageSource(curStream);
  if (imgPath.contains("String_Node_Str")) {
    is.setVideo(true);
  }
  WPImageSpan[] click_spans=s.getSpans(selectionStart,selectionEnd,WPImageSpan.class);
  if (click_spans.length != 0) {
    s.insert(selectionEnd,"String_Node_Str");
    selectionStart=selectionStart + 2;
    selectionEnd=selectionEnd + 2;
  }
  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");
  try {
    content.setSelection(s.length());
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void addMedia(String imgPath,Uri curStream){
  Bitmap resizedBitmap=null;
  ImageHelper ih=new ImageHelper();
  Display display=getWindowManager().getDefaultDisplay();
  int width=display.getWidth();
  int height=display.getHeight();
  if (width > height)   width=height;
  HashMap<String,Object> mediaData=ih.getImageBytesForPath(imgPath,EditPost.this);
  if (mediaData == null) {
    Toast.makeText(EditPost.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
    return;
  }
  BitmapFactory.Options opts=new BitmapFactory.Options();
  opts.inJustDecodeBounds=true;
  byte[] bytes=(byte[])mediaData.get("String_Node_Str");
  BitmapFactory.decodeByteArray(bytes,0,bytes.length,opts);
  float conversionFactor=0.25f;
  if (opts.outWidth > opts.outHeight)   conversionFactor=0.40f;
  byte[] finalBytes=ih.createThumbnail(bytes,String.valueOf((int)(width * conversionFactor)),(String)mediaData.get("String_Node_Str"),true);
  resizedBitmap=BitmapFactory.decodeByteArray(finalBytes,0,finalBytes.length);
  WPEditText content=(WPEditText)findViewById(R.id.postContent);
  int selectionStart=content.getSelectionStart();
  styleStart=selectionStart;
  int selectionEnd=content.getSelectionEnd();
  if (selectionStart > selectionEnd) {
    int temp=selectionEnd;
    selectionEnd=selectionStart;
    selectionStart=temp;
  }
  if (content.getText().length() == 0) {
    content.setText("String_Node_Str");
  }
  Editable s=content.getText();
  WPImageSpan is=new WPImageSpan(EditPost.this,resizedBitmap,curStream);
  String imageWidth=WordPress.currentBlog.getMaxImageWidth();
  if (!imageWidth.equals("String_Node_Str")) {
    try {
      is.setWidth(Integer.valueOf(imageWidth));
    }
 catch (    NumberFormatException e) {
      e.printStackTrace();
    }
  }
  is.setTitle((String)mediaData.get("String_Node_Str"));
  is.setImageSource(curStream);
  if (imgPath.contains("String_Node_Str")) {
    is.setVideo(true);
  }
  WPImageSpan[] click_spans=s.getSpans(selectionStart,selectionEnd,WPImageSpan.class);
  if (click_spans.length != 0) {
    s.insert(selectionEnd,"String_Node_Str");
    selectionStart=selectionStart + 2;
    selectionEnd=selectionEnd + 2;
  }
  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");
  try {
    content.setSelection(s.length());
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}