Program: 170798
Project: 170798
Buggy source:
protected static void addSpeedLimitsMenu(DownloadManager[] dms,Menu menu){
  Core core=CoreFactory.getSingleton();
  final SpeedLimitHandler slh=SpeedLimitHandler.getSingleton(core);
  boolean all_have_limit=true;
  Set<String> common_profiles=new HashSet<>();
  final List<byte[]> dm_hashes=new ArrayList<>();
  for (int i=0; i < dms.length; i++) {
    DownloadManager dm=dms[i];
    int maxul=dm.getStats().getUploadRateLimitBytesPerSecond();
    int maxdl=dm.getStats().getDownloadRateLimitBytesPerSecond();
    if (maxul == 0 && maxdl == 0) {
      all_have_limit=false;
    }
    TOTorrent t=dm.getTorrent();
    if (t == null) {
      common_profiles.clear();
    }
 else {
      try {
        byte[] hash=t.getHash();
        dm_hashes.add(hash);
        List<String> profs=slh.getProfilesForDownload(hash);
        if (i == 0) {
          common_profiles.addAll(profs);
        }
 else {
          common_profiles.retainAll(profs);
        }
      }
 catch (      TOTorrentException e) {
        Debug.out(e);
        common_profiles.clear();
      }
    }
  }
  java.util.List<String> profiles=slh.getProfileNames();
  final Menu add_to_prof_menu=new Menu(menu.getShell(),SWT.DROP_DOWN);
  MenuItem add_to_prof_item=new MenuItem(menu,SWT.CASCADE);
  add_to_prof_item.setMenu(add_to_prof_menu);
  Messages.setLanguageText(add_to_prof_item,"String_Node_Str");
  if (!all_have_limit) {
    add_to_prof_item.setEnabled(false);
  }
 else {
    for (    final String p : profiles) {
      MenuItem addItem=new MenuItem(add_to_prof_menu,SWT.PUSH);
      addItem.setText(p);
      addItem.addListener(SWT.Selection,new Listener(){
        @Override public void handleEvent(        Event arg0){
          slh.addDownloadsToProfile(p,dm_hashes);
          MenuFactory.showText("String_Node_Str",MessageText.getString("String_Node_Str",new String[]{p}),slh.getProfile(p));
        }
      }
);
    }
  }
  final Menu remove_from_prof_menu=new Menu(menu.getShell(),SWT.DROP_DOWN);
  MenuItem remove_from_prof_item=new MenuItem(menu,SWT.CASCADE);
  remove_from_prof_item.setMenu(remove_from_prof_menu);
  Messages.setLanguageText(remove_from_prof_item,"String_Node_Str");
  if (common_profiles.isEmpty()) {
    remove_from_prof_item.setEnabled(false);
  }
 else {
    for (    final String p : common_profiles) {
      MenuItem addItem=new MenuItem(remove_from_prof_menu,SWT.PUSH);
      addItem.setText(p);
      addItem.addListener(SWT.Selection,new Listener(){
        @Override public void handleEvent(        Event arg0){
          slh.removeDownloadsFromProfile(p,dm_hashes);
          MenuFactory.showText("String_Node_Str",MessageText.getString("String_Node_Str",new String[]{p}),slh.getProfile(p));
        }
      }
);
    }
  }
}

Fixed version (ground truth):
protected static void addSpeedLimitsMenu(DownloadManager[] dms,Menu menu){
  Core core=CoreFactory.getSingleton();
  Shell menu_shell=menu.getShell();
  final SpeedLimitHandler slh=SpeedLimitHandler.getSingleton(core);
  boolean all_have_limit=true;
  Set<String> common_profiles=new HashSet<>();
  final List<byte[]> dm_hashes=new ArrayList<>();
  for (int i=0; i < dms.length; i++) {
    DownloadManager dm=dms[i];
    int maxul=dm.getStats().getUploadRateLimitBytesPerSecond();
    int maxdl=dm.getStats().getDownloadRateLimitBytesPerSecond();
    if (maxul == 0 && maxdl == 0) {
      all_have_limit=false;
    }
    TOTorrent t=dm.getTorrent();
    if (t == null) {
      common_profiles.clear();
    }
 else {
      try {
        byte[] hash=t.getHash();
        dm_hashes.add(hash);
        List<String> profs=slh.getProfilesForDownload(hash);
        if (i == 0) {
          common_profiles.addAll(profs);
        }
 else {
          common_profiles.retainAll(profs);
        }
      }
 catch (      TOTorrentException e) {
        Debug.out(e);
        common_profiles.clear();
      }
    }
  }
  java.util.List<String> profiles=slh.getProfileNames();
  final Menu add_to_prof_menu=new Menu(menu_shell,SWT.DROP_DOWN);
  MenuItem add_to_prof_item=new MenuItem(menu,SWT.CASCADE);
  add_to_prof_item.setMenu(add_to_prof_menu);
  Messages.setLanguageText(add_to_prof_item,"String_Node_Str");
  if (!all_have_limit) {
    add_to_prof_item.setEnabled(false);
  }
 else {
    for (    final String p : profiles) {
      MenuItem addItem=new MenuItem(add_to_prof_menu,SWT.PUSH);
      addItem.setText(p);
      addItem.addListener(SWT.Selection,new Listener(){
        @Override public void handleEvent(        Event arg0){
          slh.addDownloadsToProfile(p,dm_hashes);
          MenuFactory.showText("String_Node_Str",MessageText.getString("String_Node_Str",new String[]{p}),slh.getProfile(p));
        }
      }
);
    }
  }
  final Menu remove_from_prof_menu=new Menu(menu_shell,SWT.DROP_DOWN);
  MenuItem remove_from_prof_item=new MenuItem(menu,SWT.CASCADE);
  remove_from_prof_item.setMenu(remove_from_prof_menu);
  Messages.setLanguageText(remove_from_prof_item,"String_Node_Str");
  if (common_profiles.isEmpty()) {
    remove_from_prof_item.setEnabled(false);
  }
 else {
    for (    final String p : common_profiles) {
      MenuItem addItem=new MenuItem(remove_from_prof_menu,SWT.PUSH);
      addItem.setText(p);
      addItem.addListener(SWT.Selection,new Listener(){
        @Override public void handleEvent(        Event arg0){
          slh.removeDownloadsFromProfile(p,dm_hashes);
          MenuFactory.showText("String_Node_Str",MessageText.getString("String_Node_Str",new String[]{p}),slh.getProfile(p));
        }
      }
);
    }
  }
}