nus-yam/ex-repair huggingface dataset:
Program: 4233
Project: 4233
Buggy source:
/** 
 * Constructs a BTMetaInfo based on the BTData.
 */
private BTMetaInfo(BTData data) throws ValueException {
  try {
    URI trackerURI=new URI(data.getAnnounce());
    if (!"String_Node_Str".equalsIgnoreCase(trackerURI.getScheme()))     throw new ValueException("String_Node_Str" + trackerURI.getScheme());
    _trackers=new URI[]{trackerURI};
  }
 catch (  URIException mue) {
    throw new ValueException("String_Node_Str" + data.getAnnounce());
  }
  _infoHash=data.getInfoHash();
  try {
    _infoHashURN=URN.createSHA1UrnFromBytes(_infoHash);
  }
 catch (  IOException impossible) {
    ErrorService.error(impossible);
  }
  _hashes=parsePieces(data.getPieces());
  data.clearPieces();
  _pieceLength=(int)data.getPieceLength().longValue();
  if (_pieceLength <= 0)   throw new ValueException("String_Node_Str" + data.getPieceLength());
  fileSystem=new TorrentFileSystem(data,_hashes.size(),_pieceLength,_infoHash);
  fullBitField=new BitFieldSet(fullSet,getNumBlocks());
  initializeDiskManager(null,false);
}

Fixed version (ground truth):
/** 
 * Constructs a BTMetaInfo based on the BTData.
 */
private BTMetaInfo(BTData data) throws IOException {
  try {
    URI trackerURI=new URI(data.getAnnounce());
    if (!"String_Node_Str".equalsIgnoreCase(trackerURI.getScheme()))     throw new ValueException("String_Node_Str" + trackerURI.getScheme());
    _trackers=new URI[]{trackerURI};
  }
 catch (  URIException mue) {
    throw new ValueException("String_Node_Str" + data.getAnnounce());
  }
  _infoHash=data.getInfoHash();
  try {
    _infoHashURN=URN.createSHA1UrnFromBytes(_infoHash);
  }
 catch (  IOException impossible) {
    ErrorService.error(impossible);
  }
  _hashes=parsePieces(data.getPieces());
  data.clearPieces();
  _pieceLength=(int)data.getPieceLength().longValue();
  if (_pieceLength <= 0)   throw new ValueException("String_Node_Str" + data.getPieceLength());
  fileSystem=new TorrentFileSystem(data,_hashes.size(),_pieceLength,_infoHash);
  fullBitField=new BitFieldSet(fullSet,getNumBlocks());
  initializeDiskManager(null,false);
}
Program: 4234
Project: 4234
Buggy source:
void moveToCompleteFolder() throws IOException {
  saveFile(_incompleteFile,_completeFile);
  FileUtils.deleteRecursive(_incompleteFile.getParentFile());
}

Fixed version (ground truth):
void moveToCompleteFolder() throws IOException {
  boolean success=_incompleteFile.renameTo(_completeFile);
  if (!success) {
    success=CommonUtils.copy(_incompleteFile,_completeFile);
    if (success)     _incompleteFile.delete();
  }
}
Program: 4236
Project: 4236
Buggy source:
void addToLibrary(){
  for (  File f : _folders)   RouterService.getFileManager().addSharedFolder(f);
  for (  File f : _files)   RouterService.getFileManager().addFileIfShared(f);
}

Fixed version (ground truth):
void addToLibrary(){
  if (_completeFile.isFile())   RouterService.getFileManager().addFileIfShared(_completeFile);
 else   if (_completeFile.isDirectory())   RouterService.getFileManager().addSharedFolder(_completeFile);
}
Program: 4237
Project: 4237
Buggy source:
public String toString(){
  return "String_Node_Str" + query + "String_Node_Str"+ hops+ "String_Node_Str";
}

Fixed version (ground truth):
public String toString(){
  return "String_Node_Str" + hops + "String_Node_Str"+ metaMask+ "String_Node_Str"+ URNs+ "String_Node_Str"+ query+ "String_Node_Str"+ xml+ "String_Node_Str";
}
Program: 4238
Project: 4238
Buggy source:
public void testQueryStringDuplicate() throws Exception {
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(filter.allow(qr));
  assertTrue(!filter.allow(qr));
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(filter.allow(qr));
synchronized (filter) {
    try {
      filter.wait(getLag("String_Node_Str") * 4);
    }
 catch (    InterruptedException e) {
    }
  }
  assertTrue(filter.allow(qr));
  assertTrue(!filter.allow(qr));
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(filter.allow(qr));
  qr.hop();
  assertTrue(filter.allow(qr));
}

Fixed version (ground truth):
public void testQueryStringDuplicate() throws Exception {
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(filter.allow(qr));
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(!filter.allow(qr));
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(filter.allow(qr));
synchronized (filter) {
    try {
      filter.wait(getLag("String_Node_Str") * 4);
    }
 catch (    InterruptedException e) {
    }
  }
  assertTrue(filter.allow(qr));
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(!filter.allow(qr));
  qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertTrue(filter.allow(qr));
  qr.hop();
  assertTrue(filter.allow(qr));
}
Program: 4239
Project: 4239
Buggy source:
/** 
 * Returns an entry strictly higher than the given key, or null if no such entry exists.
 */
protected TrieEntry<K,V> higherEntry(K key){
  int keyLength=length(key);
  if (keyLength == 0) {
    if (!root.isEmpty())     return firstEntry();
 else     if (size() > 1)     return nextEntry(firstEntry());
 else     return null;
  }
  TrieEntry<K,V> found=getNearestEntryForKey(key,keyLength);
  if (key.equals(found.key))   return nextEntry(found);
  int bitIndex=bitIndex(key,found.key);
  if (isValidBitIndex(bitIndex)) {
    TrieEntry<K,V> added=new TrieEntry<K,V>(key,null,bitIndex);
    addEntry(added,keyLength);
    incrementSize();
    TrieEntry<K,V> ceil=nextEntry(added);
    removeEntry(added);
    modCount-=2;
    return ceil;
  }
 else   if (isNullBitKey(bitIndex)) {
    if (!root.isEmpty())     return firstEntry();
 else     if (size() > 1)     return nextEntry(firstEntry());
 else     return null;
  }
 else   if (isEqualBitKey(bitIndex)) {
    return nextEntry(found);
  }
  throw new IllegalStateException("String_Node_Str" + key);
}

Fixed version (ground truth):
/** 
 * Returns an entry strictly higher than the given key, or null if no such entry exists.
 */
protected TrieEntry<K,V> higherEntry(K key){
  int keyLength=length(key);
  if (keyLength == 0) {
    if (!root.isEmpty()) {
      if (size() > 1) {
        return nextEntry(root);
      }
 else {
        return null;
      }
    }
 else {
      return firstEntry();
    }
  }
  TrieEntry<K,V> found=getNearestEntryForKey(key,keyLength);
  if (key.equals(found.key))   return nextEntry(found);
  int bitIndex=bitIndex(key,found.key);
  if (isValidBitIndex(bitIndex)) {
    TrieEntry<K,V> added=new TrieEntry<K,V>(key,null,bitIndex);
    addEntry(added,keyLength);
    incrementSize();
    TrieEntry<K,V> ceil=nextEntry(added);
    removeEntry(added);
    modCount-=2;
    return ceil;
  }
 else   if (isNullBitKey(bitIndex)) {
    if (!root.isEmpty())     return firstEntry();
 else     if (size() > 1)     return nextEntry(firstEntry());
 else     return null;
  }
 else   if (isEqualBitKey(bitIndex)) {
    return nextEntry(found);
  }
  throw new IllegalStateException("String_Node_Str" + key);
}
Program: 4241
Project: 4241
Buggy source:
private TrieEntry(K key,V value,int bitIndex){
  this.key=key;
  this.value=value;
  this.bitIndex=bitIndex;
  this.parent=null;
  this.left=this;
  this.right=null;
}

Fixed version (ground truth):
private TrieEntry(K key,V value,int bitIndex){
  this.key=key;
  this.value=value;
  this.bitIndex=bitIndex;
  this.parent=null;
  this.left=this;
  this.right=null;
  this.predecessor=this;
}
Program: 4242
Project: 4242
Buggy source:
/** 
 * Finds the subtree that contains the prefix. This is very similar to getR but with the difference that we stop the lookup if h.bitIndex > keyLength.
 */
private TrieEntry<K,V> subtree(K prefix,int offset,int length){
  TrieEntry<K,V> current=root.left;
  TrieEntry<K,V> path=root;
  while (true) {
    if (current.bitIndex <= path.bitIndex || length < current.bitIndex)     break;
    path=current;
    if (!isBitSet(prefix,length + offset,current.bitIndex + offset)) {
      current=current.left;
    }
 else {
      current=current.right;
    }
  }
  TrieEntry<K,V> entry=current.isEmpty() ? path : current;
  if (entry.isEmpty())   return null;
  int offsetLength=offset + length;
  if (isBitSet(prefix,offsetLength,offsetLength) != isBitSet(entry.key,length(entry.key),length)) {
    return null;
  }
  int bitIndex=keyAnalyzer.bitIndex(prefix,offset,length,entry.key,0,length(entry.getKey()));
  if (bitIndex >= 0 && bitIndex < length)   return null;
  return entry;
}

Fixed version (ground truth):
/** 
 * Finds the subtree that contains the prefix. This is very similar to getR but with the difference that we stop the lookup if h.bitIndex > keyLength.
 */
private TrieEntry<K,V> subtree(K prefix,int offset,int length){
  TrieEntry<K,V> current=root.left;
  TrieEntry<K,V> path=root;
  while (true) {
    if (current.bitIndex <= path.bitIndex || length < current.bitIndex)     break;
    path=current;
    if (!isBitSet(prefix,length + offset,current.bitIndex + offset)) {
      current=current.left;
    }
 else {
      current=current.right;
    }
  }
  TrieEntry<K,V> entry=current.isEmpty() ? path : current;
  if (entry.isEmpty())   return null;
  int offsetLength=offset + length;
  if (entry == root && length(entry.getKey()) < offsetLength)   return null;
  if (isBitSet(prefix,offsetLength,offsetLength) != isBitSet(entry.key,length(entry.key),length)) {
    return null;
  }
  int bitIndex=keyAnalyzer.bitIndex(prefix,offset,length,entry.key,0,length(entry.getKey()));
  if (bitIndex >= 0 && bitIndex < length)   return null;
  return entry;
}
Program: 4244
Project: 4244
Buggy source:
/** 
 * build the  QRT table call to super.buildQRT and add XML specific Strings to QRT
 */
protected void buildQRT(){
  super.buildQRT();
  for (  String string : new MultiIterable<String>(getXMLKeyWords(),getXMLIndivisibleKeyWords()))   _queryRouteTable.add(string);
}

Fixed version (ground truth):
/** 
 * build the  QRT table call to super.buildQRT and add XML specific Strings to QRT
 */
protected void buildQRT(){
  super.buildQRT();
  for (  String string : getXMLKeyWords())   _queryRouteTable.add(string);
  for (  String string : getXMLIndivisibleKeyWords())   _queryRouteTable.addIndivisible(string);
}
Program: 4246
Project: 4246
Buggy source:
/** 
 * Reads the downloaders serialized in DOWNLOAD_SNAPSHOT_FILE and adds them to this, queued.  The queued downloads will restart immediately if slots are available.  Returns false iff the file could not be read for any reason.  THIS METHOD SHOULD BE CALLED BEFORE ANY GUI ACTION.  It is public for testing purposes only!  
 * @param file the downloads.dat snapshot file 
 */
public synchronized boolean readSnapshot(File file){
  List buf=null;
  try {
    ObjectInputStream in=new ConverterObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
    buf=(List)in.readObject();
    incompleteFileManager=(IncompleteFileManager)in.readObject();
  }
 catch (  Throwable t) {
    LOG.error("String_Node_Str",t);
    return false;
  }
  buf=new LinkedList(new HashSet(buf));
  try {
    for (Iterator iter=buf.iterator(); iter.hasNext(); ) {
      ManagedDownloader downloader=(ManagedDownloader)iter.next();
      DownloadCallback dc=callback;
      if (downloader instanceof RequeryDownloader)       continue;
      waiting.add(downloader);
      downloader.initialize(this,this.fileManager,callback(downloader));
      callback(downloader).addDownload(downloader);
    }
    return true;
  }
 catch (  ClassCastException e) {
    return false;
  }
 finally {
    if (incompleteFileManager.initialPurge(getActiveDownloadFiles(buf)))     writeSnapshot();
  }
}

Fixed version (ground truth):
/** 
 * Reads the downloaders serialized in DOWNLOAD_SNAPSHOT_FILE and adds them to this, queued.  The queued downloads will restart immediately if slots are available.  Returns false iff the file could not be read for any reason.  THIS METHOD SHOULD BE CALLED BEFORE ANY GUI ACTION.  It is public for testing purposes only!  
 * @param file the downloads.dat snapshot file 
 */
public synchronized boolean readSnapshot(File file){
  List buf=null;
  try {
    ObjectInputStream in=new ConverterObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
    buf=(List)in.readObject();
    incompleteFileManager=(IncompleteFileManager)in.readObject();
  }
 catch (  Throwable t) {
    LOG.error("String_Node_Str",t);
    return false;
  }
  buf=new LinkedList(new HashSet(buf));
  try {
    for (Iterator iter=buf.iterator(); iter.hasNext(); ) {
      ManagedDownloader downloader=(ManagedDownloader)iter.next();
      if (downloader instanceof RequeryDownloader)       continue;
      waiting.add(downloader);
      downloader.initialize(this,this.fileManager,callback(downloader));
      callback(downloader).addDownload(downloader);
    }
    return true;
  }
 catch (  ClassCastException e) {
    return false;
  }
 finally {
    if (incompleteFileManager.initialPurge(getActiveDownloadFiles(buf)))     writeSnapshot();
  }
}
Program: 4247
Project: 4247
Buggy source:
/** 
 * Handles core Gnutella request/reply protocol. If asynchronous messaging is supported, this immediately returns and messages are processed asynchronously via processMessage calls.  Otherwise, if reading blocks, this  will run until the connection is closed.
 * @requires this is initialized
 * @modifies the network underlying this, manager
 * @effects receives request and sends appropriate replies.
 * @throws IOException passed on from the receive call; failures to forwardor route messages are silently swallowed, allowing the message loop to continue.
 */
void loopForMessages() throws IOException {
  supernodeClientAtLooping=isSupernodeClientConnection();
  if (!isAsynchronous()) {
    Thread.currentThread().setName("String_Node_Str");
    while (true) {
      Message m=null;
      try {
        m=receive();
        if (m == null)         continue;
        handleMessageInternal(m);
      }
 catch (      BadPacketException ignored) {
      }
    }
  }
 else {
    _socket.setSoTimeout(0);
    MessageReader reader=new MessageReader(ManagedConnection.this);
    if (isReadDeflated())     reader.setReadChannel(new InflaterReader(_inflater));
    ((NIOMultiplexor)_socket).setReadObserver(reader);
  }
}

Fixed version (ground truth):
/** 
 * Handles core Gnutella request/reply protocol. If asynchronous messaging is supported, this immediately returns and messages are processed asynchronously via processMessage calls.  Otherwise, if reading blocks, this  will run until the connection is closed.
 * @requires this is initialized
 * @modifies the network underlying this, manager
 * @effects receives request and sends appropriate replies.
 * @throws IOException passed on from the receive call; failures to forwardor route messages are silently swallowed, allowing the message loop to continue.
 */
void loopForMessages() throws IOException {
  supernodeClientAtLooping=isSupernodeClientConnection();
  if (!isAsynchronous()) {
    LOG.debug("String_Node_Str");
    Thread.currentThread().setName("String_Node_Str");
    while (true) {
      Message m=null;
      try {
        m=receive();
        if (m == null)         continue;
        handleMessageInternal(m);
      }
 catch (      BadPacketException ignored) {
      }
    }
  }
 else {
    LOG.debug("String_Node_Str");
    _socket.setSoTimeout(0);
    MessageReader reader=new MessageReader(ManagedConnection.this);
    if (isReadDeflated())     reader.setReadChannel(new InflaterReader(_inflater));
    ((NIOMultiplexor)_socket).setReadObserver(reader);
  }
}
Program: 4248
Project: 4248
Buggy source:
/** 
 * removes all Unicast Endpoints, reset associated members
 */
private void resetUnicastEndpointsAndQueries(){
  LOG.debug("String_Node_Str");
synchronized (_queries) {
    _queries.clear();
    _queries.notifyAll();
  }
synchronized (_queryHosts) {
    _queryHosts.clear();
    _queryHosts.notifyAll();
  }
synchronized (_queryKeys) {
    _queryKeys.clear();
    _queryKeys.notifyAll();
  }
synchronized (_pingList) {
    _pingList.clear();
    _pingList.notifyAll();
  }
  _lastPingTime=0;
  _testUDPPingsSent=0;
}

Fixed version (ground truth):
/** 
 * removes all Unicast Endpoints, reset associated members
 */
@SuppressWarnings("String_Node_Str") private void resetUnicastEndpointsAndQueries(){
  LOG.debug("String_Node_Str");
synchronized (_queries) {
    _queries.clear();
    _queries.notifyAll();
  }
synchronized (_queryHosts) {
    _queryHosts.clear();
    _queryHosts.notifyAll();
  }
synchronized (_queryKeys) {
    _queryKeys.clear();
    _queryKeys.notifyAll();
  }
synchronized (_pingList) {
    _pingList.clear();
    _pingList.notifyAll();
  }
  _lastPingTime=0;
  _testUDPPingsSent=0;
}
Program: 4250
Project: 4250
Buggy source:
/** 
 * Returns this Response as a RemoteFileDesc.
 */
public RemoteFileDesc toRemoteFileDesc(HostData data){
  if (cachedRFD != null && cachedRFD.getPort() == data.getPort() && cachedRFD.getHost().equals(data.getIP()))   return cachedRFD;
 else {
    RemoteFileDesc rfd=new RemoteFileDesc(data.getIP(),data.getPort(),getIndex(),getName(),(int)getSize(),data.getClientGUID(),data.getSpeed(),data.isChatEnabled(),data.getQuality(),data.isBrowseHostEnabled(),getDocument(),getUrns(),data.isReplyToMulticastQuery(),data.isFirewalled(),data.getVendorCode(),System.currentTimeMillis(),data.getPushProxies(),getCreateTime(),data.getFWTVersionSupported());
    cachedRFD=rfd;
    return rfd;
  }
}

Fixed version (ground truth):
/** 
 * Returns this Response as a RemoteFileDesc.
 */
public RemoteFileDesc toRemoteFileDesc(HostData data){
  if (cachedRFD != null && cachedRFD.getPort() == data.getPort() && cachedRFD.getHost().equals(data.getIP()))   return cachedRFD;
 else {
    RemoteFileDesc rfd=new RemoteFileDesc(data.getIP(),data.getPort(),getIndex(),getName(),(int)getSize(),data.getClientGUID(),data.getSpeed(),data.isChatEnabled(),data.getQuality(),data.isBrowseHostEnabled(),getDocument(),getUrns(),data.isReplyToMulticastQuery(),data.isFirewalled(),data.getVendorCode(),data.getPushProxies(),getCreateTime(),data.getFWTVersionSupported());
    cachedRFD=rfd;
    return rfd;
  }
}
Program: 4251
Project: 4251
Buggy source:
/** 
 * Utility method for converting the non-firewalled elements of an AlternateLocationCollection to a smaller set of endpoints.
 */
private static Set getAsEndpoints(AlternateLocationCollection col){
  if (col == null || !col.hasAlternateLocations())   return Collections.EMPTY_SET;
  long now=System.currentTimeMillis();
synchronized (col) {
    Set endpoints=null;
    int i=0;
    for (Iterator iter=col.iterator(); iter.hasNext() && i < MAX_LOCATIONS; ) {
      Object o=iter.next();
      if (!(o instanceof DirectAltLoc))       continue;
      DirectAltLoc al=(DirectAltLoc)o;
      if (al.canBeSent(AlternateLocation.MESH_RESPONSE)) {
        IpPort host=al.getHost();
        if (!NetworkUtils.isMe(host)) {
          if (endpoints == null)           endpoints=new HashSet();
          if (!(host instanceof Endpoint))           host=new Endpoint(host.getAddress(),host.getPort());
          endpoints.add(host);
          i++;
          al.send(now,AlternateLocation.MESH_RESPONSE);
        }
      }
 else       if (!al.canBeSentAny())       iter.remove();
    }
    return endpoints == null ? Collections.EMPTY_SET : endpoints;
  }
}

Fixed version (ground truth):
/** 
 * Utility method for converting the non-firewalled elements of an AlternateLocationCollection to a smaller set of endpoints.
 */
private static Set getAsEndpoints(AlternateLocationCollection col){
  if (col == null || !col.hasAlternateLocations())   return Collections.EMPTY_SET;
  long now=System.currentTimeMillis();
synchronized (col) {
    Set endpoints=null;
    int i=0;
    for (Iterator iter=col.iterator(); iter.hasNext() && i < MAX_LOCATIONS; ) {
      Object o=iter.next();
      if (!(o instanceof DirectAltLoc)) {
        if (LOG.isDebugEnabled())         LOG.debug("String_Node_Str" + o);
        continue;
      }
      DirectAltLoc al=(DirectAltLoc)o;
      if (al.canBeSent(AlternateLocation.MESH_RESPONSE)) {
        IpPort host=al.getHost();
        if (!NetworkUtils.isMe(host)) {
          if (endpoints == null)           endpoints=new HashSet();
          if (!(host instanceof Endpoint))           host=new Endpoint(host.getAddress(),host.getPort());
          endpoints.add(host);
          i++;
          al.send(now,AlternateLocation.MESH_RESPONSE);
        }
      }
 else       if (!al.canBeSentAny())       iter.remove();
    }
    return endpoints == null ? Collections.EMPTY_SET : endpoints;
  }
}
Program: 4253
Project: 4253
Buggy source:
/** 
 * Loads values from cache file, if available
 */
private Map<URN,Long> createMap(){
  ObjectInputStream ois=null;
  try {
    ois=new ConverterObjectInputStream(new BufferedInputStream(new FileInputStream(CTIME_CACHE_FILE)));
    return GenericsUtils.scanForMap(ois.readObject(),URN.class,Long.class,true);
  }
 catch (  Throwable t) {
    dirty=true;
    LOG.error("String_Node_Str",t);
    return new HashMap<URN,Long>();
  }
 finally {
    IOUtils.close(ois);
  }
}

Fixed version (ground truth):
/** 
 * Loads values from cache file, if available
 */
private Map<URN,Long> createMap(){
  ObjectInputStream ois=null;
  try {
    ois=new ConverterObjectInputStream(new BufferedInputStream(new FileInputStream(CTIME_CACHE_FILE)));
    return GenericsUtils.scanForMap(ois.readObject(),URN.class,Long.class,GenericsUtils.ScanMode.REMOVE);
  }
 catch (  Throwable t) {
    dirty=true;
    LOG.error("String_Node_Str",t);
    return new HashMap<URN,Long>();
  }
 finally {
    IOUtils.close(ois);
  }
}
Program: 4254
Project: 4254
Buggy source:
/** 
 * Helper method to install a MessageHandler in the provided Map  for the provided Message Class. See setMessageHandler(), setUDPMessageHandler() and  setMulticastMessageHandler() for implementation details.
 */
private static Map setHandler(Map handlerMap,Class clazz,MessageHandler handler){
  if (clazz == null) {
    throw new NullPointerException("String_Node_Str");
  }
  if (handler == null) {
    throw new NullPointerException("String_Node_Str");
  }
  Map copy=new IdentityHashMap(handlerMap);
  Object o=copy.put(clazz,handler);
  if (o != null && LOG.isErrorEnabled()) {
    LOG.error("String_Node_Str" + o.getClass() + "String_Node_Str"+ clazz);
  }
  return copy;
}

Fixed version (ground truth):
/** 
 * Helper method to install a MessageHandler in the provided Map  for the provided Message Class. See setMessageHandler(), setUDPMessageHandler() and  setMulticastMessageHandler() for implementation details.
 */
private static Map<Class<? extends Message>,MessageHandler> setHandler(Map<Class<? extends Message>,? extends MessageHandler> handlerMap,Class<? extends Message> clazz,MessageHandler handler){
  if (clazz == null) {
    throw new NullPointerException("String_Node_Str");
  }
  if (handler == null) {
    throw new NullPointerException("String_Node_Str");
  }
  Map<Class<? extends Message>,MessageHandler> copy=new IdentityHashMap<Class<? extends Message>,MessageHandler>(handlerMap);
  Object o=copy.put(clazz,handler);
  if (o != null && LOG.isErrorEnabled()) {
    LOG.error("String_Node_Str" + o.getClass() + "String_Node_Str"+ clazz);
  }
  return copy;
}
Program: 4255
Project: 4255
Buggy source:
/** 
 * Forwards the UDPConnectBack to neighboring peers as a UDPConnectBackRedirect request.
 */
protected void handleUDPConnectBackRequest(UDPConnectBackVendorMessage udp,Connection source){
  GUID guidToUse=udp.getConnectBackGUID();
  int portToContact=udp.getConnectBackPort();
  InetAddress sourceAddr=source.getInetAddress();
  Message msg=new UDPConnectBackRedirect(guidToUse,sourceAddr,portToContact);
  int sentTo=0;
  List peers=new ArrayList(_manager.getInitializedConnections());
  Collections.shuffle(peers);
  for (Iterator i=peers.iterator(); i.hasNext() && sentTo < MAX_UDP_CONNECTBACK_FORWARDS; ) {
    ManagedConnection currMC=(ManagedConnection)i.next();
    if (currMC == source)     continue;
    if (currMC.remoteHostSupportsUDPRedirect() >= 0) {
      currMC.send(msg);
      sentTo++;
    }
  }
}

Fixed version (ground truth):
/** 
 * Forwards the UDPConnectBack to neighboring peers as a UDPConnectBackRedirect request.
 */
protected void handleUDPConnectBackRequest(UDPConnectBackVendorMessage udp,Connection source){
  GUID guidToUse=udp.getConnectBackGUID();
  int portToContact=udp.getConnectBackPort();
  InetAddress sourceAddr=source.getInetAddress();
  Message msg=new UDPConnectBackRedirect(guidToUse,sourceAddr,portToContact);
  int sentTo=0;
  List<ManagedConnection> peers=new ArrayList<ManagedConnection>(_manager.getInitializedConnections());
  Collections.shuffle(peers);
  for (  ManagedConnection currMC : peers) {
    if (sentTo >= MAX_UDP_CONNECTBACK_FORWARDS)     break;
    if (currMC == source)     continue;
    if (currMC.remoteHostSupportsUDPRedirect() >= 0) {
      currMC.send(msg);
      sentTo++;
    }
  }
}
Program: 4256
Project: 4256
Buggy source:
/** 
 * Helper method to get a MessageHandler from the provided Map for the provided Message Class
 */
private static MessageHandler getHandler(Map messageHandlers,Class clazz){
  return (MessageHandler)messageHandlers.get(clazz);
}

Fixed version (ground truth):
/** 
 * Helper method to get a MessageHandler from the provided Map for the provided Message Class
 */
private static MessageHandler getHandler(Map<Class<? extends Message>,? extends MessageHandler> messageHandlers,Class<? extends Message> clazz){
  return messageHandlers.get(clazz);
}
Program: 4257
Project: 4257
Buggy source:
/** 
 * Installs a MessageHandler for Multicast Messages.
 * @link #handleMulticastMessage(Message, InetSocketAddress)
 * @param clazz The Class of the Message
 * @param handler The Handler of the Message
 */
public void setMulticastMessageHandler(Class clazz,MessageHandler handler){
synchronized (multicastMessageHandlers) {
    multicastMessageHandlers=setHandler(multicastMessageHandlers,clazz,handler);
  }
}

Fixed version (ground truth):
/** 
 * Installs a MessageHandler for Multicast Messages.
 * @link #handleMulticastMessage(Message, InetSocketAddress)
 * @param clazz The Class of the Message
 * @param handler The Handler of the Message
 */
public void setMulticastMessageHandler(Class<? extends Message> clazz,MessageHandler handler){
synchronized (multicastMessageHandlers) {
    multicastMessageHandlers=setHandler(multicastMessageHandlers,clazz,handler);
  }
}
Program: 4258
Project: 4258
Buggy source:
/** 
 * Abstract method for creating query hits.  Subclasses must specify how this list is created.
 * @return a <tt>List</tt> of <tt>QueryReply</tt> instances
 */
protected abstract List createQueryReply(byte[] guid,byte ttl,long speed,Response[] res,byte[] clientGUID,boolean busy,boolean uploaded,boolean measuredSpeed,boolean isFromMcast,boolean shouldMarkForFWTransfer);

Fixed version (ground truth):
/** 
 * Abstract method for creating query hits.  Subclasses must specify how this list is created.
 * @return a <tt>List</tt> of <tt>QueryReply</tt> instances
 */
protected abstract List<QueryReply> createQueryReply(byte[] guid,byte ttl,long speed,Response[] res,byte[] clientGUID,boolean busy,boolean uploaded,boolean measuredSpeed,boolean isFromMcast,boolean shouldMarkForFWTransfer);
Program: 4259
Project: 4259
Buggy source:
/** 
 * The default handler for PingRequests received in ManagedConnection.loopForMessages().  This implementation uses the ping route table to route a ping reply.  If an appropriate route doesn't exist, records the error statistics.  On sucessful routing, the PingReply count is incremented.<p> In all cases, the ping reply is recorded into the host catcher.<p> Override as desired, but you probably want to call super.handlePingReply if you do.
 */
protected void handlePingReply(PingReply reply,ReplyHandler handler){
  boolean newAddress=RouterService.getHostCatcher().add(reply);
  if (newAddress && !reply.isUDPHostCache()) {
    PongCacher.instance().addPong(reply);
  }
  ReplyHandler replyHandler=_pingRouteTable.getReplyHandler(reply.getGUID());
  if (replyHandler != null) {
    replyHandler.handlePingReply(reply,handler);
  }
 else {
    RouteErrorStat.PING_REPLY_ROUTE_ERRORS.incrementStat();
    handler.countDroppedMessage();
  }
  boolean supportsUnicast=reply.supportsUnicast();
  if (newAddress && (reply.isUltrapeer() || supportsUnicast)) {
    List list=_manager.getInitializedClientConnections();
    for (int i=0; i < list.size(); i++) {
      ManagedConnection c=(ManagedConnection)list.get(i);
      Assert.that(c != null,"String_Node_Str");
      if (c != handler && c != replyHandler && c.allowNewPongs()) {
        c.handlePingReply(reply,handler);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * The default handler for PingRequests received in ManagedConnection.loopForMessages().  This implementation uses the ping route table to route a ping reply.  If an appropriate route doesn't exist, records the error statistics.  On sucessful routing, the PingReply count is incremented.<p> In all cases, the ping reply is recorded into the host catcher.<p> Override as desired, but you probably want to call super.handlePingReply if you do.
 */
protected void handlePingReply(PingReply reply,ReplyHandler handler){
  boolean newAddress=RouterService.getHostCatcher().add(reply);
  if (newAddress && !reply.isUDPHostCache()) {
    PongCacher.instance().addPong(reply);
  }
  ReplyHandler replyHandler=_pingRouteTable.getReplyHandler(reply.getGUID());
  if (replyHandler != null) {
    replyHandler.handlePingReply(reply,handler);
  }
 else {
    RouteErrorStat.PING_REPLY_ROUTE_ERRORS.incrementStat();
    handler.countDroppedMessage();
  }
  boolean supportsUnicast=reply.supportsUnicast();
  if (newAddress && (reply.isUltrapeer() || supportsUnicast)) {
    List<ManagedConnection> list=_manager.getInitializedClientConnections();
    for (int i=0; i < list.size(); i++) {
      ManagedConnection c=list.get(i);
      Assert.that(c != null,"String_Node_Str");
      if (c != handler && c != replyHandler && c.allowNewPongs()) {
        c.handlePingReply(reply,handler);
      }
    }
  }
}
Program: 4261
Project: 4261
Buggy source:
/** 
 * @param map the map that keeps track of recent redirects
 * @param key the key which we would (have) store(d) in the map
 * @return whether we should service the redirect request
 * @modifies the map
 */
private boolean shouldServiceRedirect(FixedsizeHashMap map,Object key){
synchronized (map) {
    Object placeHolder=map.get(key);
    if (placeHolder == null) {
      try {
        map.put(key,map);
        return true;
      }
 catch (      NoMoreStorageException nomo) {
        return false;
      }
    }
 else     return false;
  }
}

Fixed version (ground truth):
/** 
 * @param map the map that keeps track of recent redirects
 * @param key the key which we would (have) store(d) in the map
 * @return whether we should service the redirect request
 * @modifies the map
 */
private boolean shouldServiceRedirect(FixedsizeHashMap<String,String> map,String key){
synchronized (map) {
    String placeHolder=map.get(key);
    if (placeHolder == null) {
      try {
        map.put(key,key);
        return true;
      }
 catch (      NoMoreStorageException nomo) {
        return false;
      }
    }
 else     return false;
  }
}
Program: 4262
Project: 4262
Buggy source:
/** 
 * Installs a MessageHandler for UDP Messages.
 * @link #handleUDPMessage(Message, InetSocketAddress)
 * @param clazz The Class of the Message
 * @param handler The Handler of the Message
 */
public void setUDPMessageHandler(Class clazz,MessageHandler handler){
synchronized (udpMessageHandlers) {
    udpMessageHandlers=setHandler(udpMessageHandlers,clazz,handler);
  }
}

Fixed version (ground truth):
/** 
 * Installs a MessageHandler for UDP Messages.
 * @link #handleUDPMessage(Message, InetSocketAddress)
 * @param clazz The Class of the Message
 * @param handler The Handler of the Message
 */
public void setUDPMessageHandler(Class<? extends Message> clazz,MessageHandler handler){
synchronized (udpMessageHandlers) {
    udpMessageHandlers=setHandler(udpMessageHandlers,clazz,handler);
  }
}
Program: 4263
Project: 4263
Buggy source:
/** 
 * Notifies any message listeners of this message's guid about the message. This holds no locks.
 */
private final void notifyMessageListener(Message msg,ReplyHandler handler){
  List all=(List)_messageListeners.get(msg.getGUID());
  if (all != null) {
    for (Iterator i=all.iterator(); i.hasNext(); ) {
      MessageListener next=(MessageListener)i.next();
      next.processMessage(msg,handler);
    }
  }
}

Fixed version (ground truth):
/** 
 * Notifies any message listeners of this message's guid about the message. This holds no locks.
 */
private final void notifyMessageListener(Message msg,ReplyHandler handler){
  List<MessageListener> all=_messageListeners.get(msg.getGUID());
  if (all != null) {
    for (    MessageListener next : all) {
      next.processMessage(msg,handler);
    }
  }
}
Program: 4264
Project: 4264
Buggy source:
/** 
 * Sends updated query routing tables to all connections which haven't been updated in a while.  You can call this method as often as you want; it takes care of throttling.
 * @modifies connections
 */
private void forwardQueryRouteTables(){
  long time=System.currentTimeMillis();
  List list=_manager.getInitializedConnections();
  QueryRouteTable table=null;
  List patches=null;
  QueryRouteTable lastSent=null;
  for (int i=0; i < list.size(); i++) {
    ManagedConnection c=(ManagedConnection)list.get(i);
    if (RouterService.isSupernode()) {
      if (!c.isUltrapeerQueryRoutingConnection()) {
        continue;
      }
    }
 else     if (!(c.isClientSupernodeConnection() && c.isQueryRoutingEnabled())) {
      continue;
    }
    if (time < c.getNextQRPForwardTime())     continue;
    c.incrementNextQRPForwardTime(time);
    if (table == null) {
      table=createRouteTable();
      _lastQueryRouteTable=table;
    }
    if (lastSent == c.getQueryRouteTableSent()) {
      if (patches == null)       patches=table.encode(lastSent,true);
    }
 else {
      lastSent=c.getQueryRouteTableSent();
      patches=table.encode(lastSent,true);
    }
    if (!ConnectionSettings.SEND_QRP.getValue()) {
      return;
    }
    for (Iterator iter=patches.iterator(); iter.hasNext(); ) {
      c.send((RouteTableMessage)iter.next());
    }
    c.setQueryRouteTableSent(table);
  }
}

Fixed version (ground truth):
/** 
 * Sends updated query routing tables to all connections which haven't been updated in a while.  You can call this method as often as you want; it takes care of throttling.
 * @modifies connections
 */
private void forwardQueryRouteTables(){
  long time=System.currentTimeMillis();
  List<ManagedConnection> list=_manager.getInitializedConnections();
  QueryRouteTable table=null;
  List<RouteTableMessage> patches=null;
  QueryRouteTable lastSent=null;
  for (int i=0; i < list.size(); i++) {
    ManagedConnection c=list.get(i);
    if (RouterService.isSupernode()) {
      if (!c.isUltrapeerQueryRoutingConnection()) {
        continue;
      }
    }
 else     if (!(c.isClientSupernodeConnection() && c.isQueryRoutingEnabled())) {
      continue;
    }
    if (time < c.getNextQRPForwardTime())     continue;
    c.incrementNextQRPForwardTime(time);
    if (table == null) {
      table=createRouteTable();
      _lastQueryRouteTable=table;
    }
    if (lastSent == c.getQueryRouteTableSent()) {
      if (patches == null)       patches=table.encode(lastSent,true);
    }
 else {
      lastSent=c.getQueryRouteTableSent();
      patches=table.encode(lastSent,true);
    }
    if (!ConnectionSettings.SEND_QRP.getValue()) {
      return;
    }
    for (    RouteTableMessage next : patches)     c.send(next);
    c.setQueryRouteTableSent(table);
  }
}
Program: 4265
Project: 4265
Buggy source:
/** 
 * Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 */
public MessageHandler getUDPMessageHandler(Class clazz){
  return getHandler(udpMessageHandlers,clazz);
}

Fixed version (ground truth):
/** 
 * Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 */
public MessageHandler getUDPMessageHandler(Class<? extends Message> clazz){
  return getHandler(udpMessageHandlers,clazz);
}
Program: 4266
Project: 4266
Buggy source:
public int getNumOOBToRequest(ReplyNumberVendorMessage reply,ReplyHandler handler){
  GUID qGUID=new GUID(reply.getGUID());
  int numResults=RouterService.getSearchResultHandler().getNumResultsForQuery(qGUID);
  if (numResults < 0)   numResults=DYNAMIC_QUERIER.getLeafResultsForQuery(qGUID);
  if ((numResults < 0) || (numResults > QueryHandler.ULTRAPEER_RESULTS)) {
    OutOfBandThroughputStat.RESPONSES_BYPASSED.addData(reply.getNumResults());
    if (!reply.canReceiveUnsolicited())     return -1;
    DownloadManager dManager=RouterService.getDownloadManager();
    if (!_callback.isQueryAlive(qGUID) && !dManager.isGuidForQueryDownloading(qGUID))     return -1;
    GUESSEndpoint ep=new GUESSEndpoint(handler.getInetAddress(),handler.getPort());
synchronized (_bypassedResults) {
      Set eps=(Set)_bypassedResults.get(qGUID);
      if (eps == null) {
        eps=new HashSet();
        _bypassedResults.put(qGUID,eps);
      }
      if (_bypassedResults.size() <= MAX_BYPASSED_RESULTS)       eps.add(ep);
    }
    return -1;
  }
  return reply.getNumResults();
}

Fixed version (ground truth):
public int getNumOOBToRequest(ReplyNumberVendorMessage reply,ReplyHandler handler){
  GUID qGUID=new GUID(reply.getGUID());
  int numResults=RouterService.getSearchResultHandler().getNumResultsForQuery(qGUID);
  if (numResults < 0)   numResults=DYNAMIC_QUERIER.getLeafResultsForQuery(qGUID);
  if ((numResults < 0) || (numResults > QueryHandler.ULTRAPEER_RESULTS)) {
    OutOfBandThroughputStat.RESPONSES_BYPASSED.addData(reply.getNumResults());
    if (!reply.canReceiveUnsolicited())     return -1;
    DownloadManager dManager=RouterService.getDownloadManager();
    if (!_callback.isQueryAlive(qGUID) && !dManager.isGuidForQueryDownloading(qGUID))     return -1;
    GUESSEndpoint ep=new GUESSEndpoint(handler.getInetAddress(),handler.getPort());
synchronized (_bypassedResults) {
      Set<GUESSEndpoint> eps=_bypassedResults.get(qGUID);
      if (eps == null) {
        eps=new HashSet<GUESSEndpoint>();
        _bypassedResults.put(qGUID,eps);
      }
      if (_bypassedResults.size() <= MAX_BYPASSED_RESULTS)       eps.add(ep);
    }
    return -1;
  }
  return reply.getNumResults();
}
Program: 4267
Project: 4267
Buggy source:
/** 
 * Forwards the query request to any leaf connections.
 * @param request the query to forward
 * @param handler the <tt>ReplyHandler</tt> that responds to therequest appropriately
 * @param manager the <tt>ConnectionManager</tt> that providesaccess to any leaf connections that we should forward to
 */
public final void forwardQueryRequestToLeaves(QueryRequest query,ReplyHandler handler){
  if (!RouterService.isSupernode())   return;
  List list=_manager.getInitializedClientConnections();
  List hitConnections=new ArrayList();
  for (int i=0; i < list.size(); i++) {
    ManagedConnection mc=(ManagedConnection)list.get(i);
    if (mc == handler)     continue;
    if (mc.shouldForwardQuery(query)) {
      hitConnections.add(mc);
    }
  }
  if (list.size() > 8 && (double)hitConnections.size() / (double)list.size() > .8) {
    int startIndex=(int)Math.floor(Math.random() * hitConnections.size() * 0.75);
    hitConnections=hitConnections.subList(startIndex,startIndex + hitConnections.size() / 4);
  }
  int notSent=list.size() - hitConnections.size();
  RoutedQueryStat.LEAF_DROP.addData(notSent);
  for (int i=0; i < hitConnections.size(); i++) {
    ManagedConnection mc=(ManagedConnection)hitConnections.get(i);
    mc.send(query);
    RoutedQueryStat.LEAF_SEND.incrementStat();
  }
}

Fixed version (ground truth):
/** 
 * Forwards the query request to any leaf connections.
 * @param request the query to forward
 * @param handler the <tt>ReplyHandler</tt> that responds to therequest appropriately
 * @param manager the <tt>ConnectionManager</tt> that providesaccess to any leaf connections that we should forward to
 */
public final void forwardQueryRequestToLeaves(QueryRequest query,ReplyHandler handler){
  if (!RouterService.isSupernode())   return;
  List<ManagedConnection> list=_manager.getInitializedClientConnections();
  List<ManagedConnection> hitConnections=new ArrayList<ManagedConnection>();
  for (int i=0; i < list.size(); i++) {
    ManagedConnection mc=list.get(i);
    if (mc == handler)     continue;
    if (mc.shouldForwardQuery(query)) {
      hitConnections.add(mc);
    }
  }
  if (list.size() > 8 && (double)hitConnections.size() / (double)list.size() > .8) {
    int startIndex=(int)Math.floor(Math.random() * hitConnections.size() * 0.75);
    hitConnections=hitConnections.subList(startIndex,startIndex + hitConnections.size() / 4);
  }
  int notSent=list.size() - hitConnections.size();
  RoutedQueryStat.LEAF_DROP.addData(notSent);
  for (int i=0; i < hitConnections.size(); i++) {
    ManagedConnection mc=hitConnections.get(i);
    mc.send(query);
    RoutedQueryStat.LEAF_SEND.incrementStat();
  }
}
Program: 4268
Project: 4268
Buggy source:
/** 
 * Broadcasts the query request to all initialized connections that are not the receivingConnection, setting up the routing to the designated QueryReplyHandler.  This is called from teh default handleQueryRequest and the default broadcastQueryRequest(QueryRequest) If different (smarter) broadcasting functionality is desired, override as desired.  If you do, note that receivingConnection may be null (for requests originating here).
 */
private void forwardQueryToUltrapeers(QueryRequest query,ReplyHandler handler){
  List list=_manager.getInitializedConnections();
  int limit=list.size();
  for (int i=0; i < limit; i++) {
    ManagedConnection mc=(ManagedConnection)list.get(i);
    forwardQueryToUltrapeer(query,handler,mc);
  }
}

Fixed version (ground truth):
/** 
 * Broadcasts the query request to all initialized connections that are not the receivingConnection, setting up the routing to the designated QueryReplyHandler.  This is called from teh default handleQueryRequest and the default broadcastQueryRequest(QueryRequest) If different (smarter) broadcasting functionality is desired, override as desired.  If you do, note that receivingConnection may be null (for requests originating here).
 */
private void forwardQueryToUltrapeers(QueryRequest query,ReplyHandler handler){
  List<ManagedConnection> list=_manager.getInitializedConnections();
  int limit=list.size();
  for (int i=0; i < limit; i++) {
    ManagedConnection mc=list.get(i);
    forwardQueryToUltrapeer(query,handler,mc);
  }
}
Program: 4269
Project: 4269
Buggy source:
/** 
 * Unregisters this MessageListener from listening to the GUID. This works by replacing the necessary maps & lists so that notifying doesn't have to hold any locks.
 */
public void unregisterMessageListener(byte[] guid,MessageListener ml){
  boolean removed=false;
synchronized (MESSAGE_LISTENER_LOCK) {
    List all=(List)_messageListeners.get(guid);
    if (all != null) {
      all=new ArrayList(all);
      if (all.remove(ml)) {
        removed=true;
        Map listeners=new TreeMap(GUID.GUID_BYTE_COMPARATOR);
        listeners.putAll(_messageListeners);
        if (all.isEmpty())         listeners.remove(guid);
 else         listeners.put(guid,Collections.unmodifiableList(all));
        _messageListeners=Collections.unmodifiableMap(listeners);
      }
    }
  }
  if (removed)   ml.unregistered(guid);
}

Fixed version (ground truth):
/** 
 * Unregisters this MessageListener from listening to the GUID. This works by replacing the necessary maps & lists so that notifying doesn't have to hold any locks.
 */
public void unregisterMessageListener(byte[] guid,MessageListener ml){
  boolean removed=false;
synchronized (MESSAGE_LISTENER_LOCK) {
    List<MessageListener> all=_messageListeners.get(guid);
    if (all != null) {
      all=new ArrayList<MessageListener>(all);
      if (all.remove(ml)) {
        removed=true;
        Map<byte[],List<MessageListener>> listeners=new TreeMap<byte[],List<MessageListener>>(GUID.GUID_BYTE_COMPARATOR);
        listeners.putAll(_messageListeners);
        if (all.isEmpty())         listeners.remove(guid);
 else         listeners.put(guid,Collections.unmodifiableList(all));
        _messageListeners=Collections.unmodifiableMap(listeners);
      }
    }
  }
  if (removed)   ml.unregistered(guid);
}
Program: 4270
Project: 4270
Buggy source:
/** 
 * Adds the specified MessageListener for messages with this GUID. You must manually unregister the listener. This works by replacing the necessary maps & lists, so that  notifying doesn't have to hold any locks.
 */
public void registerMessageListener(byte[] guid,MessageListener ml){
  ml.registered(guid);
synchronized (MESSAGE_LISTENER_LOCK) {
    Map listeners=new TreeMap(GUID.GUID_BYTE_COMPARATOR);
    listeners.putAll(_messageListeners);
    List all=(List)listeners.get(guid);
    if (all == null) {
      all=new ArrayList(1);
      all.add(ml);
    }
 else {
      List temp=new ArrayList(all.size() + 1);
      temp.addAll(all);
      all=temp;
      all.add(ml);
    }
    listeners.put(guid,Collections.unmodifiableList(all));
    _messageListeners=Collections.unmodifiableMap(listeners);
  }
}

Fixed version (ground truth):
/** 
 * Adds the specified MessageListener for messages with this GUID. You must manually unregister the listener. This works by replacing the necessary maps & lists, so that  notifying doesn't have to hold any locks.
 */
public void registerMessageListener(byte[] guid,MessageListener ml){
  ml.registered(guid);
synchronized (MESSAGE_LISTENER_LOCK) {
    Map<byte[],List<MessageListener>> listeners=new TreeMap<byte[],List<MessageListener>>(GUID.GUID_BYTE_COMPARATOR);
    listeners.putAll(_messageListeners);
    List<MessageListener> all=listeners.get(guid);
    if (all == null) {
      all=new ArrayList<MessageListener>(1);
      all.add(ml);
    }
 else {
      List<MessageListener> temp=new ArrayList<MessageListener>(all.size() + 1);
      temp.addAll(all);
      all=temp;
      all.add(ml);
    }
    listeners.put(guid,Collections.unmodifiableList(all));
    _messageListeners=Collections.unmodifiableMap(listeners);
  }
}
Program: 4271
Project: 4271
Buggy source:
/** 
 * Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 */
public MessageHandler getMulticastMessageHandler(Class clazz){
  return getHandler(multicastMessageHandlers,clazz);
}

Fixed version (ground truth):
/** 
 * Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 */
public MessageHandler getMulticastMessageHandler(Class<? extends Message> clazz){
  return getHandler(multicastMessageHandlers,clazz);
}
Program: 4272
Project: 4272
Buggy source:
public void run(){
  if (RouterService.isSupernode())   return;
  boolean isBusy=!RouterService.getUploadManager().isServiceable();
  final List connections=_manager.getInitializedConnections();
  final HopsFlowVendorMessage hops=new HopsFlowVendorMessage(isBusy ? BUSY_HOPS_FLOW : FREE_HOPS_FLOW);
  if (isBusy == _oldBusyState) {
    for (int i=0; i < connections.size(); i++) {
      ManagedConnection c=(ManagedConnection)connections.get(i);
      if (c != null && c.getConnectionTime() + 1.25 * HOPS_FLOW_INTERVAL > System.currentTimeMillis() && c.isClientSupernodeConnection())       c.send(hops);
    }
  }
 else {
    _oldBusyState=isBusy;
    for (int i=0; i < connections.size(); i++) {
      ManagedConnection c=(ManagedConnection)connections.get(i);
      if (c != null && c.isClientSupernodeConnection())       c.send(hops);
    }
  }
}

Fixed version (ground truth):
public void run(){
  if (RouterService.isSupernode())   return;
  boolean isBusy=!RouterService.getUploadManager().isServiceable();
  final List<ManagedConnection> connections=_manager.getInitializedConnections();
  final HopsFlowVendorMessage hops=new HopsFlowVendorMessage(isBusy ? BUSY_HOPS_FLOW : FREE_HOPS_FLOW);
  if (isBusy == _oldBusyState) {
    for (int i=0; i < connections.size(); i++) {
      ManagedConnection c=connections.get(i);
      if (c != null && c.getConnectionTime() + 1.25 * HOPS_FLOW_INTERVAL > System.currentTimeMillis() && c.isClientSupernodeConnection())       c.send(hops);
    }
  }
 else {
    _oldBusyState=isBusy;
    for (int i=0; i < connections.size(); i++) {
      ManagedConnection c=connections.get(i);
      if (c != null && c.isClientSupernodeConnection())       c.send(hops);
    }
  }
}