Program: 15223
Project: 15223
Buggy source:
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  if (data != null || (resultCode != RESULT_CANCELED || (requestCode == 1 || requestCode == 3))) {
    Bundle extras;
switch (requestCode) {
case 0:
      Uri imageUri=data.getData();
    String imgPath=imageUri.toString();
  addMedia(imgPath,imageUri);
break;
case 1:
if (resultCode == Activity.RESULT_OK) {
File f=new File(SD_CARD_TEMP_DIR);
try {
  Uri capturedImage=Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(),f.getAbsolutePath(),null,null));
  Log.i("String_Node_Str","String_Node_Str" + capturedImage.toString());
  f.delete();
  addMedia(capturedImage.toString(),capturedImage);
}
 catch (FileNotFoundException e) {
}
}
 else {
if (option != null) {
  Intent intent=new Intent();
  intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
  setResult(Activity.RESULT_CANCELED,intent);
  finish();
}
}
break;
case 2:
Uri videoUri=data.getData();
String videoPath=videoUri.toString();
addMedia(videoPath,videoUri);
break;
case 3:
if (resultCode == Activity.RESULT_OK) {
Uri capturedVideo=data.getData();
addMedia(capturedVideo.toString(),capturedVideo);
}
 else {
if (option != null) {
Intent intent=new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
setResult(Activity.RESULT_CANCELED,intent);
finish();
}
}
break;
case 4:
extras=data.getExtras();
String linkURL=extras.getString("String_Node_Str");
if (!linkURL.equals("String_Node_Str") && !linkURL.equals("String_Node_Str")) {
WPEditText contentText=(WPEditText)findViewById(R.id.postContent);
if (selectionStart > selectionEnd) {
int temp=selectionEnd;
selectionEnd=selectionStart;
selectionStart=temp;
}
Editable str=contentText.getText();
if (extras.getString("String_Node_Str") == null) {
if (selectionStart < selectionEnd) str.delete(selectionStart,selectionEnd);
str.insert(selectionStart,linkURL);
str.setSpan(new URLSpan(linkURL),selectionStart,selectionStart + linkURL.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contentText.setSelection(selectionStart + linkURL.length());
}
 else {
String linkText=extras.getString("String_Node_Str");
if (selectionStart < selectionEnd) str.delete(selectionStart,selectionEnd);
str.insert(selectionStart,linkText);
str.setSpan(new URLSpan(linkURL),selectionStart,selectionStart + linkText.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contentText.setSelection(selectionStart + linkText.length());
}
}
break;
}
}
}

Fixed version (ground truth):
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  if (resultCode == RESULT_CANCELED)   return;
  if (data != null || ((requestCode == 1 || requestCode == 3))) {
    Bundle extras;
switch (requestCode) {
case 0:
      Uri imageUri=data.getData();
    String imgPath=imageUri.toString();
  addMedia(imgPath,imageUri);
break;
case 1:
if (resultCode == Activity.RESULT_OK) {
File f=new File(SD_CARD_TEMP_DIR);
try {
  Uri capturedImage=Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(),f.getAbsolutePath(),null,null));
  Log.i("String_Node_Str","String_Node_Str" + capturedImage.toString());
  f.delete();
  addMedia(capturedImage.toString(),capturedImage);
}
 catch (FileNotFoundException e) {
}
catch (Exception e) {
}
}
 else {
if (option != null) {
  Intent intent=new Intent();
  intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
  setResult(Activity.RESULT_CANCELED,intent);
  finish();
}
}
break;
case 2:
Uri videoUri=data.getData();
String videoPath=videoUri.toString();
addMedia(videoPath,videoUri);
break;
case 3:
if (resultCode == Activity.RESULT_OK) {
Uri capturedVideo=data.getData();
addMedia(capturedVideo.toString(),capturedVideo);
}
 else {
if (option != null) {
Intent intent=new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
setResult(Activity.RESULT_CANCELED,intent);
finish();
}
}
break;
case 4:
extras=data.getExtras();
String linkURL=extras.getString("String_Node_Str");
if (!linkURL.equals("String_Node_Str") && !linkURL.equals("String_Node_Str")) {
WPEditText contentText=(WPEditText)findViewById(R.id.postContent);
if (selectionStart > selectionEnd) {
int temp=selectionEnd;
selectionEnd=selectionStart;
selectionStart=temp;
}
Editable str=contentText.getText();
if (extras.getString("String_Node_Str") == null) {
if (selectionStart < selectionEnd) str.delete(selectionStart,selectionEnd);
str.insert(selectionStart,linkURL);
str.setSpan(new URLSpan(linkURL),selectionStart,selectionStart + linkURL.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contentText.setSelection(selectionStart + linkURL.length());
}
 else {
String linkText=extras.getString("String_Node_Str");
if (selectionStart < selectionEnd) str.delete(selectionStart,selectionEnd);
str.insert(selectionStart,linkText);
str.setSpan(new URLSpan(linkURL),selectionStart,selectionStart + linkText.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contentText.setSelection(selectionStart + linkText.length());
}
}
break;
}
}
}