Program: 170793
Project: 170793
Buggy source:
@Override public void initialize(PluginInterface _plugin_interface){
  plugin_interface=_plugin_interface;
  MagnetURIHandler uri_handler=MagnetURIHandler.getSingleton();
  final LocaleUtilities lu=plugin_interface.getUtilities().getLocaleUtilities();
  lu.addListener(new LocaleListener(){
    @Override public void localeChanged(    Locale l){
      updateLocale(lu);
    }
  }
);
  updateLocale(lu);
  BasicPluginConfigModel config=plugin_interface.getUIManager().createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS,PLUGIN_CONFIGSECTION_ID);
  config.addInfoParameter2("String_Node_Str",String.valueOf(uri_handler.getPort()));
  secondary_lookup=config.addBooleanParameter2("String_Node_Str","String_Node_Str",true);
  md_lookup=config.addBooleanParameter2("String_Node_Str","String_Node_Str",true);
  md_lookup_delay=config.addIntParameter2("String_Node_Str","String_Node_Str",MD_LOOKUP_DELAY_SECS_DEFAULT);
  md_lookup.addEnabledOnSelection(md_lookup_delay);
  timeout_param=config.addIntParameter2("String_Node_Str","String_Node_Str",PLUGIN_DOWNLOAD_TIMEOUT_SECS_DEFAULT);
  sources_param=config.addStringListParameter2("String_Node_Str","String_Node_Str",SOURCE_VALUES,SOURCE_STRINGS,SOURCE_VALUES[1]);
  magnet_recovery=config.addBooleanParameter2("String_Node_Str","String_Node_Str",true);
  Parameter[] nps=new Parameter[AENetworkClassifier.AT_NETWORKS.length];
  for (int i=0; i < nps.length; i++) {
    String nn=AENetworkClassifier.AT_NETWORKS[i];
    String config_name="String_Node_Str" + nn;
    String msg_text="String_Node_Str" + nn;
    final BooleanParameter param=config.addBooleanParameter2(config_name,msg_text,COConfigurationManager.getBooleanParameter(config_name));
    COConfigurationManager.addParameterListener(config_name,new com.biglybt.core.config.ParameterListener(){
      @Override public void parameterChanged(      String name){
        param.setDefaultValue(COConfigurationManager.getBooleanParameter(name));
      }
    }
);
    nps[i]=param;
    net_params.put(nn,param);
  }
  config.createGroup("String_Node_Str",nps);
  MenuItemListener listener=new MenuItemListener(){
    @Override public void selected(    MenuItem _menu,    Object _target){
      TableRow[] rows=(TableRow[])_target;
      String cb_all_data="String_Node_Str";
      for (      TableRow row : rows) {
        Torrent torrent;
        String name;
        Object ds=row.getDataSource();
        Download download=null;
        ShareResource share=null;
        if (ds instanceof ShareResourceFile) {
          try {
            torrent=((ShareResourceFile)ds).getItem().getTorrent();
          }
 catch (          ShareException e) {
            continue;
          }
          name=((ShareResourceFile)ds).getName();
          share=(ShareResource)ds;
        }
 else         if (ds instanceof ShareResourceDir) {
          try {
            torrent=((ShareResourceDir)ds).getItem().getTorrent();
          }
 catch (          ShareException e) {
            continue;
          }
          name=((ShareResourceDir)ds).getName();
          share=(ShareResource)ds;
        }
 else         if (ds instanceof Download) {
          download=(Download)ds;
          torrent=download.getTorrent();
          name=download.getName();
        }
 else {
          continue;
        }
        Set<String> networks=new HashSet<>();
        if (share != null) {
          Map<String,String> properties=share.getProperties();
          String nets=properties.get(ShareManager.PR_NETWORKS);
          if (nets != null) {
            String[] bits=nets.split("String_Node_Str");
            for (            String bit : bits) {
              bit=AENetworkClassifier.internalise(bit.trim());
              if (bit != null) {
                networks.add(bit);
              }
            }
          }
        }
        if (download != null) {
          TorrentAttribute ta=plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
          String[] nets=download.getListAttribute(ta);
          networks.addAll(Arrays.asList(nets));
        }
        String cb_data=download == null ? UrlUtils.getMagnetURI(name,torrent) : UrlUtils.getMagnetURI(download);
        if (download != null) {
          List<Tag> tags=TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL,PluginCoreUtils.unwrap(download));
          for (          Tag tag : tags) {
            if (tag.isPublic()) {
              cb_data+="String_Node_Str" + UrlUtils.encode(tag.getTagName(true));
            }
          }
        }
        String sources=sources_param.getValue();
        boolean add_sources=sources.equals("String_Node_Str") || (sources.equals("String_Node_Str") && share != null);
        if (add_sources) {
          if (networks.isEmpty()) {
            for (            String net : AENetworkClassifier.AT_NETWORKS) {
              if (isNetworkEnabled(net)) {
                networks.add(net);
              }
            }
          }
          if (networks.contains(AENetworkClassifier.AT_PUBLIC) && !cb_data.contains("String_Node_Str")) {
            InetAddress ip=NetworkAdmin.getSingleton().getDefaultPublicAddress();
            InetAddress ip_v6=NetworkAdmin.getSingleton().getDefaultPublicAddressV6();
            int port=TCPNetworkManager.getSingleton().getTCPListeningPortNumber();
            if (ip != null && port > 0) {
              cb_data+="String_Node_Str" + UrlUtils.encode(ip.getHostAddress() + "String_Node_Str" + port);
            }
            if (ip_v6 != null && port > 0) {
              cb_data+="String_Node_Str" + UrlUtils.encode(ip_v6.getHostAddress() + "String_Node_Str" + port);
            }
          }
        }
        cb_all_data+=(cb_all_data.length() == 0 ? "String_Node_Str" : "String_Node_Str") + cb_data;
      }
      try {
        plugin_interface.getUIManager().copyToClipBoard(cb_all_data);
      }
 catch (      Throwable e) {
        e.printStackTrace();
      }
    }
  }
;
  final TableContextMenuItem menu1=plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE,"String_Node_Str");
  final TableContextMenuItem menu2=plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE,"String_Node_Str");
  final TableContextMenuItem menu3=plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYSHARES,"String_Node_Str");
  menu1.addMultiListener(listener);
  menu1.setHeaderCategory(MenuItem.HEADER_SOCIAL);
  menu2.addMultiListener(listener);
  menu2.setHeaderCategory(MenuItem.HEADER_SOCIAL);
  menu3.addMultiListener(listener);
  menu3.setHeaderCategory(MenuItem.HEADER_SOCIAL);
  uri_handler.addListener(new MagnetURIHandlerListener(){
    @Override public byte[] badge(){
      InputStream is=getClass().getClassLoader().getResourceAsStream("String_Node_Str");
      if (is == null) {
        return (null);
      }
      try {
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        try {
          byte[] buffer=new byte[8192];
          while (true) {
            int len=is.read(buffer);
            if (len <= 0) {
              break;
            }
            baos.write(buffer,0,len);
          }
        }
  finally {
          is.close();
        }
        return (baos.toByteArray());
      }
 catch (      Throwable e) {
        Debug.printStackTrace(e);
        return (null);
      }
    }
    @Override public byte[] download(    MagnetURIHandlerProgressListener muh_listener,    byte[] hash,    String args,    InetSocketAddress[] sources,    long timeout) throws MagnetURIHandlerException {
      try {
        Download dl=plugin_interface.getDownloadManager().getDownload(hash);
        if (dl != null) {
          Torrent torrent=dl.getTorrent();
          if (torrent != null) {
            byte[] torrent_data=torrent.writeToBEncodedData();
            torrent_data=addTrackersAndWebSeedsEtc(torrent_data,args,new HashSet<String>());
            return (torrent_data);
          }
        }
      }
 catch (      Throwable e) {
        Debug.printStackTrace(e);
      }
      return (recoverableDownload(muh_listener,hash,args,sources,timeout,false));
    }
    @Override public boolean download(    URL url) throws MagnetURIHandlerException {
      try {
        plugin_interface.getDownloadManager().addDownload(url,false);
        return (true);
      }
 catch (      DownloadException e) {
        throw (new MagnetURIHandlerException("String_Node_Str",e));
      }
    }
    @Override public boolean set(    String name,    Map values){
      List l=listeners.getList();
      for (int i=0; i < l.size(); i++) {
        if (((MagnetPluginListener)l.get(i)).set(name,values)) {
          return (true);
        }
      }
      return (false);
    }
    @Override public int get(    String name,    Map values){
      List l=listeners.getList();
      for (int i=0; i < l.size(); i++) {
        int res=((MagnetPluginListener)l.get(i)).get(name,values);
        if (res != Integer.MIN_VALUE) {
          return (res);
        }
      }
      return (Integer.MIN_VALUE);
    }
  }
);
  plugin_interface.getUIManager().addUIListener(new UIManagerListener(){
    @Override public void UIAttached(    UIInstance instance){
      if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
        try {
          Class.forName("String_Node_Str").getConstructor(new Class[]{UIInstance.class,TableContextMenuItem[].class}).newInstance(new Object[]{instance,new TableContextMenuItem[]{menu1,menu2,menu3}});
        }
 catch (        Throwable e) {
          e.printStackTrace();
        }
      }
    }
    @Override public void UIDetached(    UIInstance instance){
    }
  }
);
  final List<Download> to_delete=new ArrayList<>();
  Download[] downloads=plugin_interface.getDownloadManager().getDownloads();
  for (  Download download : downloads) {
    if (download.getFlag(Download.FLAG_METADATA_DOWNLOAD)) {
      to_delete.add(download);
    }
  }
  final AESemaphore delete_done=new AESemaphore("String_Node_Str");
  if (to_delete.size() > 0) {
    AEThread2 t=new AEThread2("String_Node_Str",true){
      @Override public void run(){
        try {
          for (          Download download : to_delete) {
            try {
              download.stop();
            }
 catch (            Throwable e) {
            }
            try {
              download.remove(true,true);
            }
 catch (            Throwable e) {
              Debug.out(e);
            }
          }
        }
  finally {
          delete_done.release();
        }
      }
    }
;
    t.start();
  }
 else {
    delete_done.release();
  }
  plugin_interface.addListener(new PluginListener(){
    @Override public void initializationComplete(){
      AEThread2 t=new AEThread2("String_Node_Str",true){
        @Override public void run(){
          delete_done.reserve();
          recoverDownloads();
          plugin_interface.getDistributedDatabase();
        }
      }
;
      t.start();
    }
    @Override public void closedownInitiated(){
    }
    @Override public void closedownComplete(){
    }
  }
);
}

Fixed version (ground truth):
@Override public void initialize(PluginInterface _plugin_interface){
  plugin_interface=_plugin_interface;
  MagnetURIHandler uri_handler=MagnetURIHandler.getSingleton();
  final LocaleUtilities lu=plugin_interface.getUtilities().getLocaleUtilities();
  lu.addListener(new LocaleListener(){
    @Override public void localeChanged(    Locale l){
      updateLocale(lu);
    }
  }
);
  updateLocale(lu);
  BasicPluginConfigModel config=plugin_interface.getUIManager().createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS,PLUGIN_CONFIGSECTION_ID);
  config.addInfoParameter2("String_Node_Str",String.valueOf(uri_handler.getPort()));
  secondary_lookup=config.addBooleanParameter2("String_Node_Str","String_Node_Str",true);
  md_lookup=config.addBooleanParameter2("String_Node_Str","String_Node_Str",true);
  md_lookup_delay=config.addIntParameter2("String_Node_Str","String_Node_Str",MD_LOOKUP_DELAY_SECS_DEFAULT);
  md_lookup.addEnabledOnSelection(md_lookup_delay);
  timeout_param=config.addIntParameter2("String_Node_Str","String_Node_Str",PLUGIN_DOWNLOAD_TIMEOUT_SECS_DEFAULT);
  sources_param=config.addStringListParameter2("String_Node_Str","String_Node_Str",SOURCE_VALUES,SOURCE_STRINGS,SOURCE_VALUES[1]);
  magnet_recovery=config.addBooleanParameter2("String_Node_Str","String_Node_Str",true);
  Parameter[] nps=new Parameter[AENetworkClassifier.AT_NETWORKS.length];
  for (int i=0; i < nps.length; i++) {
    String nn=AENetworkClassifier.AT_NETWORKS[i];
    String config_name="String_Node_Str" + nn;
    String msg_text="String_Node_Str" + nn;
    final BooleanParameter param=config.addBooleanParameter2(config_name,msg_text,COConfigurationManager.getBooleanParameter(config_name));
    COConfigurationManager.addParameterListener(config_name,new com.biglybt.core.config.ParameterListener(){
      @Override public void parameterChanged(      String name){
        param.setDefaultValue(COConfigurationManager.getBooleanParameter(name));
      }
    }
);
    nps[i]=param;
    net_params.put(nn,param);
  }
  config.createGroup("String_Node_Str",nps);
  MenuItemListener listener=new MenuItemListener(){
    @Override public void selected(    MenuItem _menu,    Object _target){
      TableRow[] rows=(TableRow[])_target;
      String cb_all_data="String_Node_Str";
      for (      TableRow row : rows) {
        Torrent torrent;
        String name;
        Object ds=row.getDataSource();
        Download download=null;
        ShareResource share=null;
        if (ds instanceof ShareResourceFile) {
          try {
            torrent=((ShareResourceFile)ds).getItem().getTorrent();
          }
 catch (          ShareException e) {
            continue;
          }
          name=((ShareResourceFile)ds).getName();
          share=(ShareResource)ds;
        }
 else         if (ds instanceof ShareResourceDir) {
          try {
            torrent=((ShareResourceDir)ds).getItem().getTorrent();
          }
 catch (          ShareException e) {
            continue;
          }
          name=((ShareResourceDir)ds).getName();
          share=(ShareResource)ds;
        }
 else         if (ds instanceof Download) {
          download=(Download)ds;
          torrent=download.getTorrent();
          name=download.getName();
        }
 else {
          continue;
        }
        boolean is_share=false;
        Set<String> networks=new HashSet<>();
        if (share != null) {
          is_share=true;
          Map<String,String> properties=share.getProperties();
          if (properties != null) {
            String nets=properties.get(ShareManager.PR_NETWORKS);
            if (nets != null) {
              String[] bits=nets.split("String_Node_Str");
              for (              String bit : bits) {
                bit=AENetworkClassifier.internalise(bit.trim());
                if (bit != null) {
                  networks.add(bit);
                }
              }
            }
          }
        }
        if (download != null) {
          TorrentAttribute ta=plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
          String[] nets=download.getListAttribute(ta);
          networks.addAll(Arrays.asList(nets));
          try {
            byte[] hash=download.getTorrentHash();
            if (plugin_interface.getShareManager().lookupShare(hash) != null) {
              is_share=true;
            }
          }
 catch (          Throwable e) {
          }
        }
        String cb_data=download == null ? UrlUtils.getMagnetURI(name,torrent) : UrlUtils.getMagnetURI(download);
        if (download != null) {
          List<Tag> tags=TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL,PluginCoreUtils.unwrap(download));
          for (          Tag tag : tags) {
            if (tag.isPublic()) {
              cb_data+="String_Node_Str" + UrlUtils.encode(tag.getTagName(true));
            }
          }
        }
        String sources=sources_param.getValue();
        boolean add_sources=sources.equals("String_Node_Str") || (sources.equals("String_Node_Str") && is_share);
        if (add_sources) {
          if (networks.isEmpty()) {
            for (            String net : AENetworkClassifier.AT_NETWORKS) {
              if (isNetworkEnabled(net)) {
                networks.add(net);
              }
            }
          }
          if (networks.contains(AENetworkClassifier.AT_PUBLIC) && !cb_data.contains("String_Node_Str")) {
            InetAddress ip=NetworkAdmin.getSingleton().getDefaultPublicAddress();
            InetAddress ip_v6=NetworkAdmin.getSingleton().getDefaultPublicAddressV6();
            int port=TCPNetworkManager.getSingleton().getTCPListeningPortNumber();
            if (ip != null && port > 0) {
              cb_data+="String_Node_Str" + UrlUtils.encode(ip.getHostAddress() + "String_Node_Str" + port);
            }
            if (ip_v6 != null && port > 0) {
              cb_data+="String_Node_Str" + UrlUtils.encode(ip_v6.getHostAddress() + "String_Node_Str" + port);
            }
          }
        }
        cb_all_data+=(cb_all_data.length() == 0 ? "String_Node_Str" : "String_Node_Str") + cb_data;
      }
      try {
        plugin_interface.getUIManager().copyToClipBoard(cb_all_data);
      }
 catch (      Throwable e) {
        e.printStackTrace();
      }
    }
  }
;
  final TableContextMenuItem menu1=plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE,"String_Node_Str");
  final TableContextMenuItem menu2=plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE,"String_Node_Str");
  final TableContextMenuItem menu3=plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYSHARES,"String_Node_Str");
  menu1.addMultiListener(listener);
  menu1.setHeaderCategory(MenuItem.HEADER_SOCIAL);
  menu2.addMultiListener(listener);
  menu2.setHeaderCategory(MenuItem.HEADER_SOCIAL);
  menu3.addMultiListener(listener);
  menu3.setHeaderCategory(MenuItem.HEADER_SOCIAL);
  uri_handler.addListener(new MagnetURIHandlerListener(){
    @Override public byte[] badge(){
      InputStream is=getClass().getClassLoader().getResourceAsStream("String_Node_Str");
      if (is == null) {
        return (null);
      }
      try {
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        try {
          byte[] buffer=new byte[8192];
          while (true) {
            int len=is.read(buffer);
            if (len <= 0) {
              break;
            }
            baos.write(buffer,0,len);
          }
        }
  finally {
          is.close();
        }
        return (baos.toByteArray());
      }
 catch (      Throwable e) {
        Debug.printStackTrace(e);
        return (null);
      }
    }
    @Override public byte[] download(    MagnetURIHandlerProgressListener muh_listener,    byte[] hash,    String args,    InetSocketAddress[] sources,    long timeout) throws MagnetURIHandlerException {
      try {
        Download dl=plugin_interface.getDownloadManager().getDownload(hash);
        if (dl != null) {
          Torrent torrent=dl.getTorrent();
          if (torrent != null) {
            byte[] torrent_data=torrent.writeToBEncodedData();
            torrent_data=addTrackersAndWebSeedsEtc(torrent_data,args,new HashSet<String>());
            return (torrent_data);
          }
        }
      }
 catch (      Throwable e) {
        Debug.printStackTrace(e);
      }
      return (recoverableDownload(muh_listener,hash,args,sources,timeout,false));
    }
    @Override public boolean download(    URL url) throws MagnetURIHandlerException {
      try {
        plugin_interface.getDownloadManager().addDownload(url,false);
        return (true);
      }
 catch (      DownloadException e) {
        throw (new MagnetURIHandlerException("String_Node_Str",e));
      }
    }
    @Override public boolean set(    String name,    Map values){
      List l=listeners.getList();
      for (int i=0; i < l.size(); i++) {
        if (((MagnetPluginListener)l.get(i)).set(name,values)) {
          return (true);
        }
      }
      return (false);
    }
    @Override public int get(    String name,    Map values){
      List l=listeners.getList();
      for (int i=0; i < l.size(); i++) {
        int res=((MagnetPluginListener)l.get(i)).get(name,values);
        if (res != Integer.MIN_VALUE) {
          return (res);
        }
      }
      return (Integer.MIN_VALUE);
    }
  }
);
  plugin_interface.getUIManager().addUIListener(new UIManagerListener(){
    @Override public void UIAttached(    UIInstance instance){
      if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
        try {
          Class.forName("String_Node_Str").getConstructor(new Class[]{UIInstance.class,TableContextMenuItem[].class}).newInstance(new Object[]{instance,new TableContextMenuItem[]{menu1,menu2,menu3}});
        }
 catch (        Throwable e) {
          e.printStackTrace();
        }
      }
    }
    @Override public void UIDetached(    UIInstance instance){
    }
  }
);
  final List<Download> to_delete=new ArrayList<>();
  Download[] downloads=plugin_interface.getDownloadManager().getDownloads();
  for (  Download download : downloads) {
    if (download.getFlag(Download.FLAG_METADATA_DOWNLOAD)) {
      to_delete.add(download);
    }
  }
  final AESemaphore delete_done=new AESemaphore("String_Node_Str");
  if (to_delete.size() > 0) {
    AEThread2 t=new AEThread2("String_Node_Str",true){
      @Override public void run(){
        try {
          for (          Download download : to_delete) {
            try {
              download.stop();
            }
 catch (            Throwable e) {
            }
            try {
              download.remove(true,true);
            }
 catch (            Throwable e) {
              Debug.out(e);
            }
          }
        }
  finally {
          delete_done.release();
        }
      }
    }
;
    t.start();
  }
 else {
    delete_done.release();
  }
  plugin_interface.addListener(new PluginListener(){
    @Override public void initializationComplete(){
      AEThread2 t=new AEThread2("String_Node_Str",true){
        @Override public void run(){
          delete_done.reserve();
          recoverDownloads();
          plugin_interface.getDistributedDatabase();
        }
      }
;
      t.start();
    }
    @Override public void closedownInitiated(){
    }
    @Override public void closedownComplete(){
    }
  }
);
}