Program: 15333
Project: 15333
Buggy source:
private static void add(final BaseActivity activity,final Menu menu,final Option option,final boolean longText){
switch (option) {
case ACCOUNTS:
    menu.add(activity.getString(R.string.options_accounts)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      final MenuItem item){
        new AccountListDialog().show(activity.getSupportFragmentManager(),null);
        return true;
      }
    }
);
  break;
case SETTINGS:
menu.add(activity.getString(R.string.options_settings)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
  public boolean onMenuItemClick(  final MenuItem item){
    final Intent intent=new Intent(activity,SettingsActivity.class);
    activity.startActivityForResult(intent,1);
    return true;
  }
}
);
break;
case CLOSE_ALL:
if (!(activity instanceof MainActivity)) {
menu.add(activity.getString(R.string.options_close_all)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
  activity.closeAllExceptMain();
  return true;
}
}
);
}
break;
case THEMES:
menu.add(activity.getString(R.string.options_theme)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(activity);
final PrefsUtility.AppearanceTheme currentTheme=PrefsUtility.appearance_theme(activity,prefs);
final String[] themeNames=activity.getResources().getStringArray(R.array.pref_appearance_theme);
final String[] themeValues=activity.getResources().getStringArray(R.array.pref_appearance_theme_return);
int selectedPos=-1;
for (int i=0; i < themeValues.length; i++) {
if (PrefsUtility.AppearanceTheme.valueOf(themeValues[i].toUpperCase()).equals(currentTheme)) {
selectedPos=i;
break;
}
}
final AlertDialog.Builder dialog=new AlertDialog.Builder(activity);
dialog.setTitle(R.string.pref_appearance_theme_title);
dialog.setSingleChoiceItems(themeNames,selectedPos,new DialogInterface.OnClickListener(){
@Override public void onClick(DialogInterface dialog,int item){
final SharedPreferences.Editor editor=prefs.edit();
editor.putString(activity.getString(R.string.pref_appearance_theme_key),themeValues[item]);
editor.apply();
dialog.dismiss();
}
}
);
final AlertDialog alert=dialog.create();
alert.show();
return true;
}
}
);
break;
case REFRESH_SUBREDDITS:
final MenuItem refreshSubreddits=menu.add(activity.getString(R.string.options_refresh_subreddits)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuSubredditsListener)activity).onRefreshSubreddits();
return true;
}
}
);
refreshSubreddits.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (!longText) refreshSubreddits.setIcon(R.drawable.ic_refresh_dark);
break;
case REFRESH_POSTS:
final MenuItem refreshPosts=menu.add(activity.getString(R.string.options_refresh_posts)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onRefreshPosts();
return true;
}
}
);
refreshPosts.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (!longText) refreshPosts.setIcon(R.drawable.ic_refresh_dark);
break;
case SUBMIT_POST:
menu.add(activity.getString(R.string.options_submit_post)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onSubmitPost();
return true;
}
}
);
break;
case SEARCH:
menu.add(Menu.NONE,Menu.NONE,1,activity.getString(R.string.action_search)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
if (activity instanceof OptionsMenuPostsListener) {
((OptionsMenuPostsListener)activity).onSearchPosts();
return true;
}
 else if (activity instanceof OptionsMenuCommentsListener) {
((OptionsMenuCommentsListener)activity).onSearchComments();
return true;
}
 else {
return false;
}
}
}
);
break;
case SEARCH_COMMENTS:
menu.add(Menu.NONE,Menu.NONE,1,activity.getString(R.string.action_search_comments)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
@Override public boolean onMenuItemClick(MenuItem item){
if (activity instanceof OptionsMenuCommentsListener) {
((OptionsMenuCommentsListener)activity).onSearchComments();
return true;
}
return false;
}
}
);
break;
case REFRESH_COMMENTS:
final MenuItem refreshComments=menu.add(activity.getString(R.string.options_refresh_comments)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuCommentsListener)activity).onRefreshComments();
return true;
}
}
);
refreshComments.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (!longText) refreshComments.setIcon(R.drawable.ic_refresh_dark);
break;
case PAST_POSTS:
menu.add(activity.getString(longText ? R.string.options_past_posts : R.string.options_past)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onPastPosts();
return true;
}
}
);
break;
case PAST_COMMENTS:
menu.add(activity.getString(longText ? R.string.options_past_comments : R.string.options_past)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuCommentsListener)activity).onPastComments();
return true;
}
}
);
break;
case SUBSCRIBE:
menu.add(activity.getString(R.string.options_subscribe)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onSubscribe();
return true;
}
}
);
break;
case UNSUBSCRIBE:
menu.add(activity.getString(R.string.options_unsubscribe)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onUnsubscribe();
return true;
}
}
);
break;
case UNSUBSCRIBING:
menu.add(activity.getString(R.string.options_unsubscribing)).setEnabled(false);
break;
case SUBSCRIBING:
menu.add(activity.getString(R.string.options_subscribing)).setEnabled(false);
break;
case SIDEBAR:
menu.add(activity.getString(R.string.options_sidebar)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onSidebar();
return true;
}
}
);
break;
case PIN:
menu.add(activity.getString(R.string.pin_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onPin();
return true;
}
}
);
break;
case UNPIN:
menu.add(activity.getString(R.string.unpin_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onUnpin();
return true;
}
}
);
break;
case BLOCK:
menu.add(activity.getString(R.string.block_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onBlock();
return true;
}
}
);
break;
case UNBLOCK:
menu.add(activity.getString(R.string.unblock_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onUnblock();
return true;
}
}
);
break;
default :
BugReportActivity.handleGlobalError(activity,"String_Node_Str");
}
}

Fixed version (ground truth):
private static void add(final BaseActivity activity,final Menu menu,final Option option,final boolean longText){
switch (option) {
case ACCOUNTS:
    menu.add(activity.getString(R.string.options_accounts)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
      public boolean onMenuItemClick(      final MenuItem item){
        new AccountListDialog().show(activity.getSupportFragmentManager(),null);
        return true;
      }
    }
);
  break;
case SETTINGS:
menu.add(activity.getString(R.string.options_settings)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
  public boolean onMenuItemClick(  final MenuItem item){
    final Intent intent=new Intent(activity,SettingsActivity.class);
    activity.startActivityForResult(intent,1);
    return true;
  }
}
);
break;
case CLOSE_ALL:
if (!(activity instanceof MainActivity)) {
menu.add(activity.getString(R.string.options_close_all)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
  activity.closeAllExceptMain();
  return true;
}
}
);
}
break;
case THEMES:
menu.add(activity.getString(R.string.options_theme)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(activity);
final PrefsUtility.AppearanceTheme currentTheme=PrefsUtility.appearance_theme(activity,prefs);
final String[] themeNames=activity.getResources().getStringArray(R.array.pref_appearance_theme);
final String[] themeValues=activity.getResources().getStringArray(R.array.pref_appearance_theme_return);
int selectedPos=-1;
for (int i=0; i < themeValues.length; i++) {
if (PrefsUtility.AppearanceTheme.valueOf(General.asciiUppercase(themeValues[i])).equals(currentTheme)) {
selectedPos=i;
break;
}
}
final AlertDialog.Builder dialog=new AlertDialog.Builder(activity);
dialog.setTitle(R.string.pref_appearance_theme_title);
dialog.setSingleChoiceItems(themeNames,selectedPos,new DialogInterface.OnClickListener(){
@Override public void onClick(DialogInterface dialog,int item){
final SharedPreferences.Editor editor=prefs.edit();
editor.putString(activity.getString(R.string.pref_appearance_theme_key),themeValues[item]);
editor.apply();
dialog.dismiss();
}
}
);
final AlertDialog alert=dialog.create();
alert.show();
return true;
}
}
);
break;
case REFRESH_SUBREDDITS:
final MenuItem refreshSubreddits=menu.add(activity.getString(R.string.options_refresh_subreddits)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuSubredditsListener)activity).onRefreshSubreddits();
return true;
}
}
);
refreshSubreddits.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (!longText) refreshSubreddits.setIcon(R.drawable.ic_refresh_dark);
break;
case REFRESH_POSTS:
final MenuItem refreshPosts=menu.add(activity.getString(R.string.options_refresh_posts)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onRefreshPosts();
return true;
}
}
);
refreshPosts.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (!longText) refreshPosts.setIcon(R.drawable.ic_refresh_dark);
break;
case SUBMIT_POST:
menu.add(activity.getString(R.string.options_submit_post)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onSubmitPost();
return true;
}
}
);
break;
case SEARCH:
menu.add(Menu.NONE,Menu.NONE,1,activity.getString(R.string.action_search)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
if (activity instanceof OptionsMenuPostsListener) {
((OptionsMenuPostsListener)activity).onSearchPosts();
return true;
}
 else if (activity instanceof OptionsMenuCommentsListener) {
((OptionsMenuCommentsListener)activity).onSearchComments();
return true;
}
 else {
return false;
}
}
}
);
break;
case SEARCH_COMMENTS:
menu.add(Menu.NONE,Menu.NONE,1,activity.getString(R.string.action_search_comments)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
@Override public boolean onMenuItemClick(MenuItem item){
if (activity instanceof OptionsMenuCommentsListener) {
((OptionsMenuCommentsListener)activity).onSearchComments();
return true;
}
return false;
}
}
);
break;
case REFRESH_COMMENTS:
final MenuItem refreshComments=menu.add(activity.getString(R.string.options_refresh_comments)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuCommentsListener)activity).onRefreshComments();
return true;
}
}
);
refreshComments.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (!longText) refreshComments.setIcon(R.drawable.ic_refresh_dark);
break;
case PAST_POSTS:
menu.add(activity.getString(longText ? R.string.options_past_posts : R.string.options_past)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onPastPosts();
return true;
}
}
);
break;
case PAST_COMMENTS:
menu.add(activity.getString(longText ? R.string.options_past_comments : R.string.options_past)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuCommentsListener)activity).onPastComments();
return true;
}
}
);
break;
case SUBSCRIBE:
menu.add(activity.getString(R.string.options_subscribe)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onSubscribe();
return true;
}
}
);
break;
case UNSUBSCRIBE:
menu.add(activity.getString(R.string.options_unsubscribe)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onUnsubscribe();
return true;
}
}
);
break;
case UNSUBSCRIBING:
menu.add(activity.getString(R.string.options_unsubscribing)).setEnabled(false);
break;
case SUBSCRIBING:
menu.add(activity.getString(R.string.options_subscribing)).setEnabled(false);
break;
case SIDEBAR:
menu.add(activity.getString(R.string.options_sidebar)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onSidebar();
return true;
}
}
);
break;
case PIN:
menu.add(activity.getString(R.string.pin_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onPin();
return true;
}
}
);
break;
case UNPIN:
menu.add(activity.getString(R.string.unpin_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onUnpin();
return true;
}
}
);
break;
case BLOCK:
menu.add(activity.getString(R.string.block_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onBlock();
return true;
}
}
);
break;
case UNBLOCK:
menu.add(activity.getString(R.string.unblock_subreddit)).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
public boolean onMenuItemClick(final MenuItem item){
((OptionsMenuPostsListener)activity).onUnblock();
return true;
}
}
);
break;
default :
BugReportActivity.handleGlobalError(activity,"String_Node_Str");
}
}