Program: 181325
Project: 181325
Buggy source:
@Override protected void onCreateContextMenu(ContextMenu menu){
  super.onCreateContextMenu(menu);
  boolean added=false;
  if (mIsInTextSelectionMode) {
    MenuHandler handler=new MenuHandler();
    if (canCut()) {
      menu.add(0,ID_CUT,0,com.android.internal.R.string.cut).setOnMenuItemClickListener(handler).setAlphabeticShortcut('x');
      added=true;
    }
    if (canCopy()) {
      menu.add(0,ID_COPY,0,com.android.internal.R.string.copy).setOnMenuItemClickListener(handler).setAlphabeticShortcut('c');
      added=true;
    }
    if (canPaste()) {
      menu.add(0,ID_PASTE,0,com.android.internal.R.string.paste).setOnMenuItemClickListener(handler).setAlphabeticShortcut('v');
      added=true;
    }
  }
 else {
    MenuHandler handler=new MenuHandler();
    if (canSelectText()) {
      menu.add(0,ID_START_SELECTING_TEXT,0,com.android.internal.R.string.selectText).setOnMenuItemClickListener(handler);
      added=true;
    }
    if (canSelectAll()) {
      menu.add(0,ID_SELECT_ALL,0,com.android.internal.R.string.selectAll).setOnMenuItemClickListener(handler).setAlphabeticShortcut('a');
      added=true;
    }
    if (mText instanceof Spanned) {
      int selStart=getSelectionStart();
      int selEnd=getSelectionEnd();
      int min=Math.min(selStart,selEnd);
      int max=Math.max(selStart,selEnd);
      URLSpan[] urls=((Spanned)mText).getSpans(min,max,URLSpan.class);
      if (urls.length == 1) {
        menu.add(0,ID_COPY_URL,0,com.android.internal.R.string.copyUrl).setOnMenuItemClickListener(handler);
        added=true;
      }
    }
    if (canPaste() && textIsOnlySpaces()) {
      menu.add(0,ID_PASTE,0,com.android.internal.R.string.paste).setOnMenuItemClickListener(handler).setAlphabeticShortcut('v');
      added=true;
    }
    if (isInputMethodTarget()) {
      menu.add(1,ID_SWITCH_INPUT_METHOD,0,com.android.internal.R.string.inputMethod).setOnMenuItemClickListener(handler);
      added=true;
    }
    String word=getWordForDictionary();
    if (word != null) {
      menu.add(1,ID_ADD_TO_DICTIONARY,0,getContext().getString(com.android.internal.R.string.addToDictionary,word)).setOnMenuItemClickListener(handler);
      added=true;
    }
  }
  if (added) {
    menu.setHeaderTitle(com.android.internal.R.string.editTextMenuTitle);
  }
}

Fixed version (ground truth):
@Override protected void onCreateContextMenu(ContextMenu menu){
  super.onCreateContextMenu(menu);
  boolean added=false;
  if (mIsInTextSelectionMode) {
    MenuHandler handler=new MenuHandler();
    if (canCut()) {
      menu.add(0,ID_CUT,0,com.android.internal.R.string.cut).setOnMenuItemClickListener(handler).setAlphabeticShortcut('x');
      added=true;
    }
    if (canCopy()) {
      menu.add(0,ID_COPY,0,com.android.internal.R.string.copy).setOnMenuItemClickListener(handler).setAlphabeticShortcut('c');
      added=true;
    }
    if (canPaste()) {
      menu.add(0,ID_PASTE,0,com.android.internal.R.string.paste).setOnMenuItemClickListener(handler).setAlphabeticShortcut('v');
      added=true;
    }
  }
 else {
    MenuHandler handler=new MenuHandler();
    if (canSelectText()) {
      menu.add(0,ID_START_SELECTING_TEXT,0,com.android.internal.R.string.selectText).setOnMenuItemClickListener(handler);
      menu.add(0,ID_SELECT_ALL,0,com.android.internal.R.string.selectAll).setOnMenuItemClickListener(handler).setAlphabeticShortcut('a');
      added=true;
    }
    if (mText instanceof Spanned) {
      int selStart=getSelectionStart();
      int selEnd=getSelectionEnd();
      int min=Math.min(selStart,selEnd);
      int max=Math.max(selStart,selEnd);
      URLSpan[] urls=((Spanned)mText).getSpans(min,max,URLSpan.class);
      if (urls.length == 1) {
        menu.add(0,ID_COPY_URL,0,com.android.internal.R.string.copyUrl).setOnMenuItemClickListener(handler);
        added=true;
      }
    }
    if (canPaste()) {
      menu.add(0,ID_PASTE,0,com.android.internal.R.string.paste).setOnMenuItemClickListener(handler).setAlphabeticShortcut('v');
      added=true;
    }
    if (isInputMethodTarget()) {
      menu.add(1,ID_SWITCH_INPUT_METHOD,0,com.android.internal.R.string.inputMethod).setOnMenuItemClickListener(handler);
      added=true;
    }
    String word=getWordForDictionary();
    if (word != null) {
      menu.add(1,ID_ADD_TO_DICTIONARY,0,getContext().getString(com.android.internal.R.string.addToDictionary,word)).setOnMenuItemClickListener(handler);
      added=true;
    }
  }
  if (added) {
    menu.setHeaderTitle(com.android.internal.R.string.editTextMenuTitle);
  }
}