Program: 15040
Project: 15040
Buggy source:
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  if (resultCode == RESULT_CANCELED) {
    if (mQuickMediaType >= 0) {
      setResult(Activity.RESULT_CANCELED,new Intent());
      finish();
    }
    if (mFormatBar.getVisibility() == View.VISIBLE)     hideFormatBar();
    return;
  }
  if (data != null || ((requestCode == RequestCode.ACTIVITY_REQUEST_CODE_TAKE_PHOTO || requestCode == RequestCode.ACTIVITY_REQUEST_CODE_TAKE_VIDEO))) {
    Bundle extras;
switch (requestCode) {
case RequestCode.ACTIVITY_REQUEST_CODE_PICTURE_LIBRARY:
      Uri imageUri=data.getData();
    verifyImage(imageUri);
  break;
case RequestCode.ACTIVITY_REQUEST_CODE_TAKE_PHOTO:
if (resultCode == Activity.RESULT_OK) {
  try {
    File f=new File(mMediaCapturePath);
    Uri capturedImageUri=Uri.fromFile(f);
    f=null;
    if (!addMedia(capturedImageUri,null))     Toast.makeText(EditPostActivity.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("String_Node_Str" + Environment.getExternalStorageDirectory())));
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
catch (  OutOfMemoryError e) {
    e.printStackTrace();
  }
}
break;
case RequestCode.ACTIVITY_REQUEST_CODE_VIDEO_LIBRARY:
Uri videoUri=data.getData();
if (!addMedia(videoUri,null)) Toast.makeText(EditPostActivity.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
break;
case RequestCode.ACTIVITY_REQUEST_CODE_TAKE_VIDEO:
if (resultCode == Activity.RESULT_OK) {
File f=new File(mMediaCapturePath);
Uri capturedVideoUri=Uri.fromFile(f);
f=null;
if (!addMedia(capturedVideoUri,null)) Toast.makeText(EditPostActivity.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
}
break;
case ACTIVITY_REQUEST_CODE_CREATE_LINK:
try {
extras=data.getExtras();
String linkURL=extras.getString("String_Node_Str");
if (!linkURL.equals("String_Node_Str") && !linkURL.equals("String_Node_Str")) {
if (mSelectionStart > mSelectionEnd) {
int temp=mSelectionEnd;
mSelectionEnd=mSelectionStart;
mSelectionStart=temp;
}
Editable str=mContentEditText.getText();
if (mLocalDraft) {
if (extras.getString("String_Node_Str") == null) {
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
str.insert(mSelectionStart,linkURL);
str.setSpan(new URLSpan(linkURL),mSelectionStart,mSelectionStart + linkURL.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContentEditText.setSelection(mSelectionStart + linkURL.length());
}
 else {
String linkText=extras.getString("String_Node_Str");
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
str.insert(mSelectionStart,linkText);
str.setSpan(new URLSpan(linkURL),mSelectionStart,mSelectionStart + linkText.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContentEditText.setSelection(mSelectionStart + linkText.length());
}
}
 else {
if (extras.getString("String_Node_Str") == null) {
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
String urlHTML="String_Node_Str" + linkURL + "String_Node_Str"+ linkURL+ "String_Node_Str";
str.insert(mSelectionStart,urlHTML);
mContentEditText.setSelection(mSelectionStart + urlHTML.length());
}
 else {
String linkText=extras.getString("String_Node_Str");
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
String urlHTML="String_Node_Str" + linkURL + "String_Node_Str"+ linkText+ "String_Node_Str";
str.insert(mSelectionStart,urlHTML);
mContentEditText.setSelection(mSelectionStart + urlHTML.length());
}
}
}
}
 catch (Exception e) {
e.printStackTrace();
}
break;
case ACTIVITY_REQUEST_CODE_SELECT_CATEGORIES:
extras=data.getExtras();
mCategories=(ArrayList<String>)extras.getSerializable("String_Node_Str");
populateSelectedCategories();
break;
}
}
}

Fixed version (ground truth):
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  if (resultCode == RESULT_CANCELED) {
    if (mQuickMediaType >= 0) {
      setResult(Activity.RESULT_CANCELED,new Intent());
      finish();
    }
    if (mFormatBar.getVisibility() == View.VISIBLE)     hideFormatBar();
    return;
  }
  if (data != null || ((requestCode == RequestCode.ACTIVITY_REQUEST_CODE_TAKE_PHOTO || requestCode == RequestCode.ACTIVITY_REQUEST_CODE_TAKE_VIDEO))) {
    Bundle extras;
switch (requestCode) {
case RequestCode.ACTIVITY_REQUEST_CODE_PICTURE_LIBRARY:
      Uri imageUri=data.getData();
    verifyImage(imageUri);
  break;
case RequestCode.ACTIVITY_REQUEST_CODE_TAKE_PHOTO:
if (resultCode == Activity.RESULT_OK) {
  try {
    File f=new File(mMediaCapturePath);
    Uri capturedImageUri=Uri.fromFile(f);
    f=null;
    if (!addMedia(capturedImageUri,null))     Toast.makeText(EditPostActivity.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("String_Node_Str" + Environment.getExternalStorageDirectory())));
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
catch (  OutOfMemoryError e) {
    e.printStackTrace();
  }
}
break;
case RequestCode.ACTIVITY_REQUEST_CODE_VIDEO_LIBRARY:
Uri videoUri=data.getData();
if (!addMedia(videoUri,null)) Toast.makeText(EditPostActivity.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
break;
case RequestCode.ACTIVITY_REQUEST_CODE_TAKE_VIDEO:
if (resultCode == Activity.RESULT_OK) {
Uri capturedVideoUri=MediaUtils.getLastRecordedVideoUri(this);
if (!addMedia(capturedVideoUri,null)) Toast.makeText(EditPostActivity.this,getResources().getText(R.string.gallery_error),Toast.LENGTH_SHORT).show();
}
break;
case ACTIVITY_REQUEST_CODE_CREATE_LINK:
try {
extras=data.getExtras();
String linkURL=extras.getString("String_Node_Str");
if (!linkURL.equals("String_Node_Str") && !linkURL.equals("String_Node_Str")) {
if (mSelectionStart > mSelectionEnd) {
int temp=mSelectionEnd;
mSelectionEnd=mSelectionStart;
mSelectionStart=temp;
}
Editable str=mContentEditText.getText();
if (mLocalDraft) {
if (extras.getString("String_Node_Str") == null) {
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
str.insert(mSelectionStart,linkURL);
str.setSpan(new URLSpan(linkURL),mSelectionStart,mSelectionStart + linkURL.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContentEditText.setSelection(mSelectionStart + linkURL.length());
}
 else {
String linkText=extras.getString("String_Node_Str");
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
str.insert(mSelectionStart,linkText);
str.setSpan(new URLSpan(linkURL),mSelectionStart,mSelectionStart + linkText.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContentEditText.setSelection(mSelectionStart + linkText.length());
}
}
 else {
if (extras.getString("String_Node_Str") == null) {
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
String urlHTML="String_Node_Str" + linkURL + "String_Node_Str"+ linkURL+ "String_Node_Str";
str.insert(mSelectionStart,urlHTML);
mContentEditText.setSelection(mSelectionStart + urlHTML.length());
}
 else {
String linkText=extras.getString("String_Node_Str");
if (mSelectionStart < mSelectionEnd) str.delete(mSelectionStart,mSelectionEnd);
String urlHTML="String_Node_Str" + linkURL + "String_Node_Str"+ linkText+ "String_Node_Str";
str.insert(mSelectionStart,urlHTML);
mContentEditText.setSelection(mSelectionStart + urlHTML.length());
}
}
}
}
 catch (Exception e) {
e.printStackTrace();
}
break;
case ACTIVITY_REQUEST_CODE_SELECT_CATEGORIES:
extras=data.getExtras();
mCategories=(ArrayList<String>)extras.getSerializable("String_Node_Str");
populateSelectedCategories();
break;
}
}
}