Program: 15410
Project: 15410
Buggy source:
@Override public boolean onContextItemSelected(MenuItem item){
  final AdapterView.AdapterContextMenuInfo info=(AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
  if (info.position <= 0) {
    return false;
  }
  final Object selectedObject=lv.getAdapter().getItem(info.position);
  if (!(selectedObject instanceof RedditCommentListItem) || !((RedditCommentListItem)selectedObject).isComment()) {
    return false;
  }
  final Action action=Action.values()[item.getItemId()];
  final RedditPreparedComment comment=((RedditCommentListItem)selectedObject).asComment();
switch (action) {
case UPVOTE:
    comment.action(getSupportActivity(),RedditAPI.RedditAction.UPVOTE);
  break;
case DOWNVOTE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.DOWNVOTE);
break;
case UNVOTE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.UNVOTE);
break;
case SAVE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.SAVE);
break;
case UNSAVE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.UNSAVE);
break;
case REPORT:
new AlertDialog.Builder(getSupportActivity()).setTitle(R.string.action_report).setMessage(R.string.action_report_sure).setPositiveButton(R.string.action_report,new DialogInterface.OnClickListener(){
public void onClick(final DialogInterface dialog,final int which){
comment.action(getSupportActivity(),RedditAPI.RedditAction.REPORT);
}
}
).setNegativeButton(R.string.dialog_cancel,null).show();
break;
case REPLY:
{
final Intent intent=new Intent(getSupportActivity(),CommentReplyActivity.class);
intent.putExtra("String_Node_Str",comment.idAndType);
startActivity(intent);
break;
}
case EDIT:
{
final Intent intent=new Intent(getSupportActivity(),CommentEditActivity.class);
intent.putExtra("String_Node_Str",comment.idAndType);
intent.putExtra("String_Node_Str",StringEscapeUtils.unescapeHtml4(comment.src.body));
startActivity(intent);
break;
}
case COMMENT_LINKS:
final HashSet<String> linksInComment=comment.computeAllLinks();
if (linksInComment.isEmpty()) {
General.quickToast(getSupportActivity(),R.string.error_toast_no_urls_in_comment);
}
 else {
final String[] linksArr=linksInComment.toArray(new String[linksInComment.size()]);
final AlertDialog.Builder builder=new AlertDialog.Builder(getSupportActivity());
builder.setItems(linksArr,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
LinkHandler.onLinkClicked(getSupportActivity(),linksArr[which],false);
dialog.dismiss();
}
}
);
final AlertDialog alert=builder.create();
alert.setTitle(R.string.action_comment_links);
alert.setCanceledOnTouchOutside(true);
alert.show();
}
break;
case SHARE:
final Intent mailer=new Intent(Intent.ACTION_SEND);
mailer.setType("String_Node_Str");
mailer.putExtra(Intent.EXTRA_SUBJECT,"String_Node_Str" + comment.src.author + "String_Node_Str");
mailer.putExtra(Intent.EXTRA_TEXT,StringEscapeUtils.unescapeHtml4(comment.src.body));
startActivityForResult(Intent.createChooser(mailer,getSupportActivity().getString(R.string.action_share)),1);
break;
case COPY:
ClipboardManager manager=(ClipboardManager)getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body));
break;
case COLLAPSE:
if (comment.getBoundView() != null) handleCommentVisibilityToggle(comment.getBoundView());
break;
case USER_PROFILE:
LinkHandler.onLinkClicked(getSupportActivity(),new UserProfileURL(comment.src.author).toString());
break;
case PROPERTIES:
CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity());
break;
case GO_TO_COMMENT:
{
PostCommentListingURL url=new PostCommentListingURL(null,comment.src.link_id,comment.idAlone,null,null,null);
LinkHandler.onLinkClicked(getSupportActivity(),url.toString());
break;
}
case CONTEXT:
{
PostCommentListingURL url=new PostCommentListingURL(null,comment.src.link_id,comment.idAlone,3,null,null);
LinkHandler.onLinkClicked(getSupportActivity(),url.toString());
break;
}
}
return true;
}

Fixed version (ground truth):
@Override public boolean onContextItemSelected(MenuItem item){
  final AdapterView.AdapterContextMenuInfo info=(AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
  if (info.position <= 0) {
    return false;
  }
  final Object selectedObject=lv.getAdapter().getItem(info.position);
  if (!(selectedObject instanceof RedditCommentListItem) || !((RedditCommentListItem)selectedObject).isComment()) {
    return false;
  }
  final Action action=Action.values()[item.getItemId()];
  final RedditPreparedComment comment=((RedditCommentListItem)selectedObject).asComment();
switch (action) {
case UPVOTE:
    comment.action(getSupportActivity(),RedditAPI.RedditAction.UPVOTE);
  break;
case DOWNVOTE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.DOWNVOTE);
break;
case UNVOTE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.UNVOTE);
break;
case SAVE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.SAVE);
break;
case UNSAVE:
comment.action(getSupportActivity(),RedditAPI.RedditAction.UNSAVE);
break;
case REPORT:
new AlertDialog.Builder(getSupportActivity()).setTitle(R.string.action_report).setMessage(R.string.action_report_sure).setPositiveButton(R.string.action_report,new DialogInterface.OnClickListener(){
public void onClick(final DialogInterface dialog,final int which){
comment.action(getSupportActivity(),RedditAPI.RedditAction.REPORT);
}
}
).setNegativeButton(R.string.dialog_cancel,null).show();
break;
case REPLY:
{
final Intent intent=new Intent(getSupportActivity(),CommentReplyActivity.class);
intent.putExtra("String_Node_Str",comment.idAndType);
startActivity(intent);
break;
}
case EDIT:
{
final Intent intent=new Intent(getSupportActivity(),CommentEditActivity.class);
intent.putExtra("String_Node_Str",comment.idAndType);
intent.putExtra("String_Node_Str",StringEscapeUtils.unescapeHtml4(comment.src.body));
startActivity(intent);
break;
}
case COMMENT_LINKS:
final HashSet<String> linksInComment=comment.computeAllLinks();
if (linksInComment.isEmpty()) {
General.quickToast(getSupportActivity(),R.string.error_toast_no_urls_in_comment);
}
 else {
final String[] linksArr=linksInComment.toArray(new String[linksInComment.size()]);
final AlertDialog.Builder builder=new AlertDialog.Builder(getSupportActivity());
builder.setItems(linksArr,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
LinkHandler.onLinkClicked(getSupportActivity(),linksArr[which],false);
dialog.dismiss();
}
}
);
final AlertDialog alert=builder.create();
alert.setTitle(R.string.action_comment_links);
alert.setCanceledOnTouchOutside(true);
alert.show();
}
break;
case SHARE:
final Intent mailer=new Intent(Intent.ACTION_SEND);
mailer.setType("String_Node_Str");
mailer.putExtra(Intent.EXTRA_SUBJECT,"String_Node_Str" + comment.src.author + "String_Node_Str");
mailer.putExtra(Intent.EXTRA_TEXT,StringEscapeUtils.unescapeHtml4(comment.src.body));
startActivityForResult(Intent.createChooser(mailer,getSupportActivity().getString(R.string.action_share)),1);
break;
case COPY:
ClipboardManager manager=(ClipboardManager)getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body));
break;
case COLLAPSE:
if (comment.getBoundView() != null) {
handleCommentVisibilityToggle(comment.getBoundView());
}
 else {
General.quickToast(getSupportActivity(),"String_Node_Str");
}
break;
case USER_PROFILE:
LinkHandler.onLinkClicked(getSupportActivity(),new UserProfileURL(comment.src.author).toString());
break;
case PROPERTIES:
CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity());
break;
case GO_TO_COMMENT:
{
PostCommentListingURL url=new PostCommentListingURL(null,comment.src.link_id,comment.idAlone,null,null,null);
LinkHandler.onLinkClicked(getSupportActivity(),url.toString());
break;
}
case CONTEXT:
{
PostCommentListingURL url=new PostCommentListingURL(null,comment.src.link_id,comment.idAlone,3,null,null);
LinkHandler.onLinkClicked(getSupportActivity(),url.toString());
break;
}
}
return true;
}