nus-yam/ex-repair huggingface dataset:
Program: 4307
Project: 4307
Buggy source:
/** 
 * like allowConnection, except more strict - if this is a leaf, only allow connections whom we have told we're leafs.
 * @return whether the connection should be allowed 
 */
private boolean allowInitializedConnection(Connection c){
  if ((isShieldedLeaf() || !isSupernode()) && !c.isClientSupernodeConnection())   return false;
  return allowConnection(c.headers());
}

Fixed version (ground truth):
/** 
 * Like allowConnection, but more more strict. In addition to allowConnection, this checks to see if the connection is a leaf, and if so only allows it if we said we're it's supernode. It also makes sure that we don't have any duplicate connections to this particular host.  (Duplicate connections are checked by IP address and 'listen port', if a listen port was specified.)
 * @return whether the connection should be allowed 
 */
private boolean allowInitializedConnection(ManagedConnection c){
  if ((isShieldedLeaf() || !isSupernode()) && !c.isClientSupernodeConnection())   return false;
  List connections=getConnections();
  int listenPort=c.getListeningPort();
  String addr=c.getAddress();
  for (int i=0; i < connections.size(); i++) {
    ManagedConnection mc=(ManagedConnection)connections.get(i);
    if (mc == c)     continue;
    if (addr.equals(mc.getAddress())) {
      int mcLP=mc.getListeningPort();
      if (listenPort == -1 || mcLP == -1 || mcLP == listenPort)       return false;
    }
  }
  return allowConnection(c.headers()).isAcceptable();
}
Program: 4308
Project: 4308
Buggy source:
/** 
 * Completes the process of initializing an externally generated connection.
 * @param c
 * @throws IOException
 */
private void completeInitializeExternallyGeneratedConnection(ManagedConnection c) throws IOException {
  processConnectionHeaders(c);
  if (!c.isOutgoing() && !allowConnection(c)) {
    throw new IOException("String_Node_Str");
  }
  if (!c.isOutgoing()) {
synchronized (this) {
      connectionInitializingIncoming(c);
      adjustConnectionFetchers();
    }
    RouterService.getCallback().connectionInitializing(c);
  }
  completeConnectionInitialization(c,false);
}

Fixed version (ground truth):
/** 
 * Completes the process of initializing an externally generated connection.
 * @param c
 * @throws IOException
 * @return true if the connection should continue, false if it was closed
 */
private boolean completeInitializeExternallyGeneratedConnection(ManagedConnection c) throws IOException {
  processConnectionHeaders(c);
  if (!c.isOutgoing() && !allowConnection(c).isAcceptable()) {
    throw new IOException("String_Node_Str");
  }
  if (!c.isOutgoing()) {
synchronized (this) {
      connectionInitializingIncoming(c);
      adjustConnectionFetchers();
    }
    RouterService.getCallback().connectionInitializing(c);
  }
  return completeConnectionInitialization(c,false);
}
Program: 4309
Project: 4309
Buggy source:
/** 
 * Performs the steps necessary to complete connection initialization.
 * @param mc the <tt>ManagedConnection</tt> to finish initializing
 * @param fetched Specifies whether or not this connection is was fetched by a connection fetcher. If so, thisremoves that connection from the list of fetched connections being initialized, keeping the connection fetcher data in sync
 */
private void completeConnectionInitialization(ManagedConnection mc,boolean fetched){
synchronized (this) {
    if (fetched) {
      _initializingFetchedConnections.remove(mc);
    }
    boolean connectionOpen=connectionInitialized(mc);
    if (connectionOpen) {
      RouterService.getCallback().connectionInitialized(mc);
      setPreferredConnections();
    }
  }
}

Fixed version (ground truth):
/** 
 * Performs the steps necessary to complete connection initialization.
 * @param mc the <tt>ManagedConnection</tt> to finish initializing
 * @param fetched Specifies whether or not this connection is was fetched by a connection fetcher. If so, thisremoves that connection from the list of fetched connections being initialized, keeping the connection fetcher data in sync
 * @return true if the connection should continue, false if it was closed
 */
private boolean completeConnectionInitialization(ManagedConnection mc,boolean fetched){
synchronized (this) {
    if (fetched) {
      _initializingFetchedConnections.remove(mc);
    }
    boolean connectionOpen=connectionInitialized(mc);
    if (connectionOpen) {
      RouterService.getCallback().connectionInitialized(mc);
      setPreferredConnections();
    }
    return connectionOpen;
  }
}
Program: 4310
Project: 4310
Buggy source:
/** 
 * Callback that Sockets.connect worked. 
 */
public void handleConnect(){
  completeConnectionInitialization(connection,true);
  processConnectionHeaders(connection);
  _lastSuccessfulConnect=System.currentTimeMillis();
  _catcher.doneWithConnect(endpoint,true);
  if (_pref)   _needPref=false;
  try {
    startConnection(connection);
  }
 catch (  IOException ignored) {
  }
}

Fixed version (ground truth):
/** 
 * Callback that handshaking has succeeded and we're all connected and ready. 
 */
public void handleConnect(){
  boolean stillOpen=completeConnectionInitialization(connection,true);
  processConnectionHeaders(connection);
  _lastSuccessfulConnect=System.currentTimeMillis();
  _catcher.doneWithConnect(endpoint,true);
  if (_pref)   _needPref=false;
  try {
    if (stillOpen)     startConnection(connection);
  }
 catch (  IOException ignored) {
  }
}
Program: 4311
Project: 4311
Buggy source:
/** 
 * Checks if the connection received can be accepted, based upon the type of connection (e.g. client, ultrapeer, temporary etc).
 * @param c The connection we received, for which totest if we have incoming slot.
 * @return true, if we have incoming slot for the connection received,false otherwise
 */
public boolean allowConnectionAsLeaf(HandshakeResponse hr){
  return allowConnection(hr,true);
}

Fixed version (ground truth):
/** 
 * Checks if the connection received can be accepted, based upon the type of connection (e.g. client, ultrapeer, temporary etc).
 * @param c The connection we received, for which totest if we have incoming slot.
 * @return true, if we have incoming slot for the connection received,false otherwise
 */
public HandshakeStatus allowConnectionAsLeaf(HandshakeResponse hr){
  return allowConnection(hr,true);
}
Program: 4313
Project: 4313
Buggy source:
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects an  outgoing leaf connection.  This occurs when we, as a leaf, reject a  connection on the third stage of the handshake.
 * @return a new <tt>HandshakeResponse</tt> instance rejecting the connection and with no extra headers
 */
static HandshakeResponse createLeafRejectOutgoingResponse(){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,HandshakeResponse.SHIELDED_MESSAGE);
}

Fixed version (ground truth):
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects an  outgoing leaf connection.  This occurs when we, as a leaf, reject a  connection on the third stage of the handshake.
 * @return a new <tt>HandshakeResponse</tt> instance rejecting the connection and with no extra headers
 */
static HandshakeResponse createLeafRejectOutgoingResponse(HandshakeStatus status){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,status.getMessage());
}
Program: 4314
Project: 4314
Buggy source:
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects the potential connection.  The returned <tt>HandshakeResponse</tt> DOES NOT include the X-Try-Ultrapeers header because this is an outgoing connection, and we should not send host data that the remote client does not request.
 * @param headers the <tt>Properties</tt> instance containing the headersto send to the node we're rejecting
 */
static HandshakeResponse createRejectOutgoingResponse(){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,HandshakeResponse.SLOTS_FULL_MESSAGE,new Properties());
}

Fixed version (ground truth):
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects the potential connection.  The returned <tt>HandshakeResponse</tt> DOES NOT include the X-Try-Ultrapeers header because this is an outgoing connection, and we should not send host data that the remote client does not request.
 * @param headers the <tt>Properties</tt> instance containing the headersto send to the node we're rejecting
 */
static HandshakeResponse createRejectOutgoingResponse(HandshakeStatus status){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,status.getMessage(),new Properties());
}
Program: 4316
Project: 4316
Buggy source:
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects the potential connection to a leaf.  We add hosts that we know about with free connection slots to the X-Try-Ultrapeers header.
 * @param headers the <tt>Properties</tt> instance containing the headersto send to the node we're rejecting
 * @param hr the <tt>HandshakeResponse</tt> containing the headers of theremote host
 * @return a new <tt>HandshakeResponse</tt> instance rejecting the connection and with the specified connection headers
 */
static HandshakeResponse createLeafRejectIncomingResponse(HandshakeResponse hr){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,HandshakeResponse.SHIELDED_MESSAGE,addXTryHeader(hr,new Properties()));
}

Fixed version (ground truth):
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects the potential connection to a leaf.  We add hosts that we know about with free connection slots to the X-Try-Ultrapeers header.
 * @param headers the <tt>Properties</tt> instance containing the headersto send to the node we're rejecting
 * @param hr the <tt>HandshakeResponse</tt> containing the headers of theremote host
 * @return a new <tt>HandshakeResponse</tt> instance rejecting the connection and with the specified connection headers
 */
static HandshakeResponse createLeafRejectIncomingResponse(HandshakeResponse hr,HandshakeStatus status){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,status.getMessage(),addXTryHeader(hr,new Properties()));
}
Program: 4317
Project: 4317
Buggy source:
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects the potential connection.  This includes the X-Try-Ultrapeers header to tell the remote host about other nodes to connect to.  We return the hosts we most recently knew to have free leaf or ultrapeer connection slots.
 * @param hr the <tt>HandshakeResponse</tt> containing the connectionheaders of the connecting host
 * @return a <tt>HandshakeResponse</tt> with the appropriate response headers
 */
static HandshakeResponse createUltrapeerRejectIncomingResponse(HandshakeResponse hr){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,HandshakeResponse.SLOTS_FULL_MESSAGE,addXTryHeader(hr,new Properties()));
}

Fixed version (ground truth):
/** 
 * Creates a new <tt>HandshakeResponse</tt> instance that rejects the potential connection.  This includes the X-Try-Ultrapeers header to tell the remote host about other nodes to connect to.  We return the hosts we most recently knew to have free leaf or ultrapeer connection slots.
 * @param hr the <tt>HandshakeResponse</tt> containing the connectionheaders of the connecting host
 * @return a <tt>HandshakeResponse</tt> with the appropriate response headers
 */
static HandshakeResponse createUltrapeerRejectIncomingResponse(HandshakeResponse hr,HandshakeStatus status){
  return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,status.getMessage(),addXTryHeader(hr,new Properties()));
}
Program: 4318
Project: 4318
Buggy source:
/** 
 * Responds to an incoming connection handshake.
 * @return the <tt>HandshakeResponse</tt> with the handshake headers to send in response to the connection attempt
 */
protected HandshakeResponse respondToIncoming(HandshakeResponse hr){
  if (hr.isCrawler()) {
    HandshakingStat.INCOMING_CRAWLER.incrementStat();
    return HandshakeResponse.createCrawlerResponse();
  }
  if (!hr.isUltrapeer()) {
    HandshakingStat.LEAF_INCOMING_REJECT.incrementStat();
    return HandshakeResponse.createLeafRejectOutgoingResponse();
  }
  Properties ret=new LeafHeaders(getRemoteIP());
  if (!_manager.allowConnection(hr)) {
    HandshakingStat.LEAF_INCOMING_REJECT.incrementStat();
    return HandshakeResponse.createLeafRejectIncomingResponse(hr);
  }
  if (hr.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  HandshakingStat.LEAF_INCOMING_ACCEPT.incrementStat();
  return HandshakeResponse.createAcceptIncomingResponse(hr,ret);
}

Fixed version (ground truth):
/** 
 * Responds to an incoming connection handshake.
 * @return the <tt>HandshakeResponse</tt> with the handshake headers to send in response to the connection attempt
 */
protected HandshakeResponse respondToIncoming(HandshakeResponse hr){
  if (hr.isCrawler()) {
    HandshakingStat.INCOMING_CRAWLER.incrementStat();
    return HandshakeResponse.createCrawlerResponse();
  }
  if (!hr.isUltrapeer()) {
    HandshakingStat.LEAF_INCOMING_REJECT.incrementStat();
    return HandshakeResponse.createLeafRejectOutgoingResponse(HandshakeStatus.WE_ARE_LEAVES);
  }
  Properties ret=new LeafHeaders(getRemoteIP());
  HandshakeStatus status=_manager.allowConnection(hr);
  if (!status.isAcceptable()) {
    HandshakingStat.LEAF_INCOMING_REJECT.incrementStat();
    return HandshakeResponse.createLeafRejectIncomingResponse(hr,status);
  }
  if (hr.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  HandshakingStat.LEAF_INCOMING_ACCEPT.incrementStat();
  return HandshakeResponse.createAcceptIncomingResponse(hr,ret);
}
Program: 4319
Project: 4319
Buggy source:
/** 
 * Responds to an outgoing connection handshake.
 * @return the <tt>HandshakeResponse</tt> with the handshake headers to send in response to the connection attempt
 */
protected HandshakeResponse respondToOutgoing(HandshakeResponse response){
  if (!response.isUltrapeer()) {
    HandshakingStat.LEAF_OUTGOING_REJECT_LEAF.incrementStat();
    return HandshakeResponse.createLeafRejectOutgoingResponse();
  }
  if (getLocalePreferencing()) {
    if (!ApplicationSettings.LANGUAGE.getValue().equals(response.getLocalePref())) {
      return HandshakeResponse.createLeafRejectLocaleOutgoingResponse();
    }
  }
  if (!_manager.allowConnection(response)) {
    HandshakingStat.LEAF_OUTGOING_REJECT_OLD_UP.incrementStat();
    return HandshakeResponse.createLeafRejectOutgoingResponse();
  }
  Properties ret=new Properties();
  if (response.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  HandshakingStat.LEAF_OUTGOING_ACCEPT.incrementStat();
  return HandshakeResponse.createAcceptOutgoingResponse(ret);
}

Fixed version (ground truth):
/** 
 * Responds to an outgoing connection handshake.
 * @return the <tt>HandshakeResponse</tt> with the handshake headers to send in response to the connection attempt
 */
protected HandshakeResponse respondToOutgoing(HandshakeResponse response){
  if (!response.isUltrapeer()) {
    HandshakingStat.LEAF_OUTGOING_REJECT_LEAF.incrementStat();
    return HandshakeResponse.createLeafRejectOutgoingResponse(HandshakeStatus.WE_ARE_LEAVES);
  }
  if (getLocalePreferencing()) {
    if (!ApplicationSettings.LANGUAGE.getValue().equals(response.getLocalePref())) {
      return HandshakeResponse.createLeafRejectLocaleOutgoingResponse();
    }
  }
  HandshakeStatus status=_manager.allowConnection(response);
  if (!status.isAcceptable()) {
    HandshakingStat.LEAF_OUTGOING_REJECT_OLD_UP.incrementStat();
    return HandshakeResponse.createLeafRejectOutgoingResponse(status);
  }
  Properties ret=new Properties();
  if (response.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  HandshakingStat.LEAF_OUTGOING_ACCEPT.incrementStat();
  return HandshakeResponse.createAcceptOutgoingResponse(ret);
}
Program: 4320
Project: 4320
Buggy source:
/** 
 * Returns true if this incoming connections should be rejected with a 503. 
 */
private boolean reject(HandshakeResponse response,Properties ret){
  boolean allowedAsLeaf=_manager.allowConnectionAsLeaf(response);
  if (response.isLeaf()) {
    if (!allowedAsLeaf)     HandshakingStat.UP_INCOMING_REJECT_LEAF.incrementStat();
 else     HandshakingStat.UP_INCOMING_ACCEPT_LEAF.incrementStat();
    return !allowedAsLeaf;
  }
  boolean supernodeNeeded=_manager.supernodeNeeded();
  if (allowedAsLeaf && !supernodeNeeded) {
    HandshakingStat.UP_INCOMING_GUIDED.incrementStat();
    ret.put(HeaderNames.X_ULTRAPEER_NEEDED,Boolean.FALSE.toString());
    return false;
  }
  boolean allowedAsUltrapeer=_manager.allowConnection(response);
  if (allowedAsUltrapeer) {
    HandshakingStat.UP_INCOMING_ACCEPT_UP.incrementStat();
    ret.put(HeaderNames.X_ULTRAPEER_NEEDED,Boolean.TRUE.toString());
    return false;
  }
  if (!allowedAsLeaf)   HandshakingStat.UP_INCOMING_REJECT_NO_ROOM_LEAF.incrementStat();
 else   HandshakingStat.UP_INCOMING_REJECT_NO_ROOM_UP.incrementStat();
  return true;
}

Fixed version (ground truth):
/** 
 * Returns a HandshakeStatus to be used for rejecting. 
 */
private HandshakeStatus reject(HandshakeResponse response,Properties ret){
  HandshakeStatus leafStatus=_manager.allowConnectionAsLeaf(response);
  boolean allowedAsLeaf=leafStatus.isAcceptable();
  if (response.isLeaf()) {
    if (!allowedAsLeaf)     HandshakingStat.UP_INCOMING_REJECT_LEAF.incrementStat();
 else     HandshakingStat.UP_INCOMING_ACCEPT_LEAF.incrementStat();
    return leafStatus;
  }
  boolean supernodeNeeded=_manager.supernodeNeeded();
  if (allowedAsLeaf && !supernodeNeeded) {
    HandshakingStat.UP_INCOMING_GUIDED.incrementStat();
    ret.put(HeaderNames.X_ULTRAPEER_NEEDED,Boolean.FALSE.toString());
    return HandshakeStatus.OK;
  }
  HandshakeStatus upStatus=_manager.allowConnection(response);
  boolean allowedAsUltrapeer=upStatus.isAcceptable();
  if (allowedAsUltrapeer) {
    HandshakingStat.UP_INCOMING_ACCEPT_UP.incrementStat();
    ret.put(HeaderNames.X_ULTRAPEER_NEEDED,Boolean.TRUE.toString());
    return upStatus;
  }
  if (!allowedAsLeaf) {
    HandshakingStat.UP_INCOMING_REJECT_NO_ROOM_LEAF.incrementStat();
    return leafStatus;
  }
 else {
    HandshakingStat.UP_INCOMING_REJECT_NO_ROOM_UP.incrementStat();
    return upStatus;
  }
}
Program: 4321
Project: 4321
Buggy source:
/** 
 * Respond to an incoming connection request.
 * @param response the headers read from the connection
 */
protected HandshakeResponse respondToIncoming(HandshakeResponse response){
  if (response.isCrawler()) {
    HandshakingStat.INCOMING_CRAWLER.incrementStat();
    return HandshakeResponse.createCrawlerResponse();
  }
  Properties ret=new UltrapeerHeaders(getRemoteIP());
  ret.put(HeaderNames.LISTEN_IP,NetworkUtils.ip2string(RouterService.getAddress()) + "String_Node_Str" + RouterService.getPort());
  if (reject(response,ret)) {
    return HandshakeResponse.createUltrapeerRejectIncomingResponse(response);
  }
  if (response.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  return HandshakeResponse.createAcceptIncomingResponse(response,ret);
}

Fixed version (ground truth):
/** 
 * Respond to an incoming connection request.
 * @param response the headers read from the connection
 */
protected HandshakeResponse respondToIncoming(HandshakeResponse response){
  if (response.isCrawler()) {
    HandshakingStat.INCOMING_CRAWLER.incrementStat();
    return HandshakeResponse.createCrawlerResponse();
  }
  Properties ret=new UltrapeerHeaders(getRemoteIP());
  ret.put(HeaderNames.LISTEN_IP,NetworkUtils.ip2string(RouterService.getAddress()) + "String_Node_Str" + RouterService.getPort());
  HandshakeStatus status=reject(response,ret);
  if (!status.isAcceptable()) {
    return HandshakeResponse.createUltrapeerRejectIncomingResponse(response,status);
  }
  if (response.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  return HandshakeResponse.createAcceptIncomingResponse(response,ret);
}
Program: 4322
Project: 4322
Buggy source:
/** 
 * Respond to an outgoing connection request.
 * @param response the headers read from the connection
 */
protected HandshakeResponse respondToOutgoing(HandshakeResponse response){
  if (!_manager.allowConnection(response)) {
    HandshakingStat.UP_OUTGOING_REJECT_FULL.incrementStat();
    return HandshakeResponse.createRejectOutgoingResponse();
  }
  Properties ret=new Properties();
  if (response.hasLeafGuidance()) {
    if (_manager.allowLeafDemotion() && response.isGoodUltrapeer()) {
      HandshakingStat.UP_OUTGOING_GUIDANCE_FOLLOWED.incrementStat();
      ret.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
    }
 else {
      HandshakingStat.UP_OUTGOING_GUIDANCE_IGNORED.incrementStat();
    }
  }
 else   HandshakingStat.UP_OUTGOING_ACCEPT.incrementStat();
  if (response.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  return HandshakeResponse.createAcceptOutgoingResponse(ret);
}

Fixed version (ground truth):
/** 
 * Respond to an outgoing connection request.
 * @param response the headers read from the connection
 */
protected HandshakeResponse respondToOutgoing(HandshakeResponse response){
  HandshakeStatus status=_manager.allowConnection(response);
  if (!status.isAcceptable()) {
    HandshakingStat.UP_OUTGOING_REJECT_FULL.incrementStat();
    return HandshakeResponse.createRejectOutgoingResponse(status);
  }
  Properties ret=new Properties();
  if (response.hasLeafGuidance()) {
    if (_manager.allowLeafDemotion() && response.isGoodUltrapeer()) {
      HandshakingStat.UP_OUTGOING_GUIDANCE_FOLLOWED.incrementStat();
      ret.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
    }
 else {
      HandshakingStat.UP_OUTGOING_GUIDANCE_IGNORED.incrementStat();
    }
  }
 else   HandshakingStat.UP_OUTGOING_ACCEPT.incrementStat();
  if (response.isDeflateAccepted()) {
    ret.put(HeaderNames.CONTENT_ENCODING,HeaderNames.DEFLATE_VALUE);
  }
  return HandshakeResponse.createAcceptOutgoingResponse(ret);
}
Program: 4323
Project: 4323
Buggy source:
/** 
 * Test to make sure that Ultrapeer headers are created correctly.
 */
public void testUltrapeerHeaders() throws Exception {
  ConnectionSettings.ACCEPT_DEFLATE.setValue(true);
  Properties headers=new Properties();
  headers.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  HandshakeResponse client=HandshakeResponse.createResponse(headers);
  HandshakeResponse hr=HandshakeResponse.createUltrapeerRejectIncomingResponse(client);
  runRejectHeadersTest(hr);
  hr=HandshakeResponse.createAcceptIncomingResponse(HandshakeResponse.createEmptyResponse(),new UltrapeerHeaders("String_Node_Str"));
  runUltrapeerHeadersTest(hr);
  headers=new Properties();
  headers.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  client=HandshakeResponse.createResponse(headers);
  ConnectionSettings.ACCEPT_DEFLATE.setValue(false);
  hr=HandshakeResponse.createUltrapeerRejectIncomingResponse(client);
  runRejectHeadersTest(hr);
  hr=HandshakeResponse.createAcceptIncomingResponse(HandshakeResponse.createEmptyResponse(),new UltrapeerHeaders("String_Node_Str"));
  runUltrapeerHeadersTest(hr);
}

Fixed version (ground truth):
/** 
 * Test to make sure that Ultrapeer headers are created correctly.
 */
public void testUltrapeerHeaders() throws Exception {
  ConnectionSettings.ACCEPT_DEFLATE.setValue(true);
  Properties headers=new Properties();
  headers.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  HandshakeResponse client=HandshakeResponse.createResponse(headers);
  HandshakeResponse hr=HandshakeResponse.createUltrapeerRejectIncomingResponse(client,HandshakeStatus.DISCONNECTED);
  runRejectHeadersTest(hr);
  hr=HandshakeResponse.createAcceptIncomingResponse(HandshakeResponse.createEmptyResponse(),new UltrapeerHeaders("String_Node_Str"));
  runUltrapeerHeadersTest(hr);
  headers=new Properties();
  headers.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  client=HandshakeResponse.createResponse(headers);
  ConnectionSettings.ACCEPT_DEFLATE.setValue(false);
  hr=HandshakeResponse.createUltrapeerRejectIncomingResponse(client,HandshakeStatus.DISCONNECTED);
  runRejectHeadersTest(hr);
  hr=HandshakeResponse.createAcceptIncomingResponse(HandshakeResponse.createEmptyResponse(),new UltrapeerHeaders("String_Node_Str"));
  runUltrapeerHeadersTest(hr);
}
Program: 4324
Project: 4324
Buggy source:
/** 
 * Test to make sure that leaf headers are created correctly.
 */
public void testLeafHeaders() throws Exception {
  ConnectionSettings.ENCODE_DEFLATE.setValue(true);
  ConnectionSettings.ACCEPT_DEFLATE.setValue(true);
  Properties headers=new Properties();
  headers.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  HandshakeResponse client=HandshakeResponse.createResponse(headers);
  HandshakeResponse hr=HandshakeResponse.createUltrapeerRejectIncomingResponse(client);
  runRejectHeadersTest(hr);
  hr=HandshakeResponse.createAcceptIncomingResponse(HandshakeResponse.createEmptyResponse(),new LeafHeaders("String_Node_Str"));
  runLeafHeadersTest(hr);
  ConnectionSettings.ACCEPT_DEFLATE.setValue(false);
  hr=HandshakeResponse.createRejectOutgoingResponse();
  runRejectOutgoingLeafHeadersTest(hr);
  hr=HandshakeResponse.createAcceptOutgoingResponse(new LeafHeaders("String_Node_Str"));
  runLeafHeadersTest(hr);
}

Fixed version (ground truth):
/** 
 * Test to make sure that leaf headers are created correctly.
 */
public void testLeafHeaders() throws Exception {
  ConnectionSettings.ENCODE_DEFLATE.setValue(true);
  ConnectionSettings.ACCEPT_DEFLATE.setValue(true);
  Properties headers=new Properties();
  headers.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  HandshakeResponse client=HandshakeResponse.createResponse(headers);
  HandshakeResponse hr=HandshakeResponse.createUltrapeerRejectIncomingResponse(client,HandshakeStatus.DISCONNECTED);
  runRejectHeadersTest(hr);
  hr=HandshakeResponse.createAcceptIncomingResponse(HandshakeResponse.createEmptyResponse(),new LeafHeaders("String_Node_Str"));
  runLeafHeadersTest(hr);
  ConnectionSettings.ACCEPT_DEFLATE.setValue(false);
  hr=HandshakeResponse.createRejectOutgoingResponse(HandshakeStatus.DISCONNECTED);
  runRejectOutgoingLeafHeadersTest(hr);
  hr=HandshakeResponse.createAcceptOutgoingResponse(new LeafHeaders("String_Node_Str"));
  runLeafHeadersTest(hr);
}
Program: 4325
Project: 4325
Buggy source:
public void testLeafRejectIncoming() throws Exception {
  Properties props=new Properties();
  props.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  HostCatcher hc=RouterService.getHostCatcher();
  hc.add(MessageTestUtils.createPongWithFreeLeafSlots());
  HandshakeResponse headers=HandshakeResponse.createResponse(props);
  HandshakeResponse hr=HandshakeResponse.createLeafRejectIncomingResponse(headers);
  assertTrue(hr.hasXTryUltrapeers());
}

Fixed version (ground truth):
public void testLeafRejectIncoming() throws Exception {
  Properties props=new Properties();
  props.put(HeaderNames.X_ULTRAPEER,"String_Node_Str");
  HostCatcher hc=RouterService.getHostCatcher();
  hc.add(MessageTestUtils.createPongWithFreeLeafSlots());
  HandshakeResponse headers=HandshakeResponse.createResponse(props);
  HandshakeResponse hr=HandshakeResponse.createLeafRejectIncomingResponse(headers,HandshakeStatus.NO_HEADERS);
  assertTrue(hr.hasXTryUltrapeers());
}
Program: 4326
Project: 4326
Buggy source:
public void run(){
  _manager.unregisterPushObserver(mrfd,true);
}

Fixed version (ground truth):
public void run(){
  _manager.unregisterPushObserver(details,true);
}
Program: 4327
Project: 4327
Buggy source:
/** 
 * Attempts to asynchronously connect through TCP to the remote end. This will return immediately and the given observer will be notified of success or failure.
 */
private void connectDirectly(DirectConnector observer){
  if (!_interrupted) {
    LOG.trace("String_Node_Str" + _rfd);
    _connectObserver=observer;
    try {
      Socket socket=Sockets.connect(_rfd.getHost(),_rfd.getPort(),NORMAL_CONNECT_TIME,observer);
      if (!observer.isShutdown())       observer.setSocket(socket);
    }
 catch (    IOException iox) {
      observer.shutdown();
    }
  }
 else {
    _manager.workerFinished(this);
  }
}

Fixed version (ground truth):
/** 
 * Attempts to asynchronously connect through TCP to the remote end. This will return immediately and the given observer will be notified of success or failure.
 */
private void connectDirectly(DirectConnector observer){
  if (!_interrupted) {
    if (LOG.isTraceEnabled())     LOG.trace("String_Node_Str" + _rfd);
    _connectObserver=observer;
    try {
      Socket socket=Sockets.connect(_rfd.getHost(),_rfd.getPort(),NORMAL_CONNECT_TIME,observer);
      if (!observer.isShutdown())       observer.setSocket(socket);
    }
 catch (    IOException iox) {
      observer.shutdown();
    }
  }
 else {
    _manager.workerFinished(this);
  }
}
Program: 4328
Project: 4328
Buggy source:
/** 
 * Attempts to connect by using a push to the remote end. This method will return immediately and the given observer will be notified of success or failure.
 */
private void connectWithPush(HTTPConnectObserver observer){
  if (!_interrupted) {
    LOG.trace("String_Node_Str" + _rfd);
    _connectObserver=null;
    final MiniRemoteFileDesc mrfd=new MiniRemoteFileDesc(_rfd.getFileName(),_rfd.getIndex(),_rfd.getClientGUID());
    _manager.registerPushObserver(observer,mrfd);
    RouterService.getDownloadManager().sendPush(_rfd,observer);
    RouterService.schedule(new Runnable(){
      public void run(){
        _manager.unregisterPushObserver(mrfd,true);
      }
    }
,_rfd.isFromAlternateLocation() ? UDP_PUSH_CONNECT_TIME : PUSH_CONNECT_TIME,0);
  }
 else {
    _manager.workerFinished(this);
  }
}

Fixed version (ground truth):
/** 
 * Attempts to connect by using a push to the remote end. This method will return immediately and the given observer will be notified of success or failure.
 */
private void connectWithPush(PushConnector observer){
  if (!_interrupted) {
    if (LOG.isTraceEnabled())     LOG.trace("String_Node_Str" + _rfd);
    _connectObserver=null;
    final PushDetails details=new PushDetails(_rfd.getClientGUID(),_rfd.getHost());
    observer.setPushDetails(details);
    _manager.registerPushObserver(observer,details);
    RouterService.getDownloadManager().sendPush(_rfd,observer);
    RouterService.schedule(new Runnable(){
      public void run(){
        _manager.unregisterPushObserver(details,true);
      }
    }
,_rfd.isFromAlternateLocation() ? UDP_PUSH_CONNECT_TIME : PUSH_CONNECT_TIME,0);
  }
 else {
    _manager.workerFinished(this);
  }
}
Program: 4329
Project: 4329
Buggy source:
/** 
 * Possibly tells the manager to forget this RFD, cleans up various things, and tells the manager to forget this worker.
 */
private void failed(){
  _manager.unregisterPushObserver(new MiniRemoteFileDesc(_rfd),false);
  if (!directConnectOnFailure) {
    if (forgetOnFailure) {
      _manager.forgetRFD(_rfd);
    }
    finishConnect();
    _manager.workerFinished(DownloadWorker.this);
  }
 else {
    connectDirectly(new DirectConnector(false));
  }
}

Fixed version (ground truth):
/** 
 * Possibly tells the manager to forget this RFD, cleans up various things, and tells the manager to forget this worker.
 */
private void failed(){
  _manager.unregisterPushObserver(pushDetails,false);
  if (!directConnectOnFailure) {
    if (forgetOnFailure) {
      _manager.forgetRFD(_rfd);
    }
    finishConnect();
    _manager.workerFinished(DownloadWorker.this);
  }
 else {
    connectDirectly(new DirectConnector(false));
  }
}
Program: 4330
Project: 4330
Buggy source:
/** 
 * Accepts a push download.  If this chooses to download the given file (with given index and clientGUID) from socket, returns true.  In this case, the caller may not make any modifications to the socket.  If this rejects the given file, returns false without modifying this or socket. Non-blocking.
 * @modifies this, socket
 * @requires GIV string (and nothing else) has been read from socket
 */
public boolean acceptDownload(String file,Socket socket,int index,byte[] clientGUID){
  if (stopped)   return false;
  MiniRemoteFileDesc mrfd=new MiniRemoteFileDesc(file,index,clientGUID);
  HTTPConnectObserver observer=(HTTPConnectObserver)pushObservers.remove(mrfd);
  if (observer == null)   return false;
  observer.handleConnect(socket);
  return true;
}

Fixed version (ground truth):
/** 
 * Accepts a push download.  If this chooses to download the given file (with given index and clientGUID) from socket, returns true.  In this case, the caller may not make any modifications to the socket.  If this rejects the given file, returns false without modifying this or socket. Non-blocking.
 * @modifies this, socket
 * @requires GIV string (and nothing else) has been read from socket
 */
public boolean acceptDownload(String file,Socket socket,int index,byte[] clientGUID){
  if (stopped)   return false;
  HTTPConnectObserver observer=pushes.getHostFor(clientGUID,socket.getInetAddress().getHostAddress());
  if (observer != null)   observer.handleConnect(socket);
  return observer != null;
}
Program: 4331
Project: 4331
Buggy source:
/** 
 * Kills all workers & shuts down all push waiters.
 */
private void killAllWorkers(){
  List workers=getAllWorkers();
  for (Iterator iter=workers.iterator(); iter.hasNext(); ) {
    DownloadWorker doomed=(DownloadWorker)iter.next();
    doomed.interrupt();
  }
  Map pushers;
synchronized (pushObservers) {
    pushers=new HashMap(pushObservers);
    pushObservers.clear();
  }
  for (Iterator i=pushers.values().iterator(); i.hasNext(); ) {
    HTTPConnectObserver next=(HTTPConnectObserver)i.next();
    next.shutdown();
  }
}

Fixed version (ground truth):
/** 
 * Kills all workers & shuts down all push waiters.
 */
private void killAllWorkers(){
  List workers=getAllWorkers();
  for (Iterator iter=workers.iterator(); iter.hasNext(); ) {
    DownloadWorker doomed=(DownloadWorker)iter.next();
    doomed.interrupt();
  }
  List pushObservers=pushes.getAllAndClear();
  for (Iterator i=pushObservers.iterator(); i.hasNext(); ) {
    HTTPConnectObserver next=(HTTPConnectObserver)i.next();
    next.shutdown();
  }
}
Program: 4333
Project: 4333
Buggy source:
/** 
 * Unregisters a ConnectObserver that was waiting for the given MRFD.  If shutdown is true and the observer was still registered, calls shutdown on that observer.
 * @param mrfd
 * @param shutdown
 */
void unregisterPushObserver(MiniRemoteFileDesc mrfd,boolean shutdown){
  HTTPConnectObserver observer=(HTTPConnectObserver)pushObservers.remove(mrfd);
  if (observer != null && shutdown)   observer.shutdown();
}

Fixed version (ground truth):
/** 
 * Unregisters a ConnectObserver that was waiting for the given MRFD.  If shutdown is true and the observer was still registered, calls shutdown on that observer.
 * @param mrfd
 * @param shutdown
 */
void unregisterPushObserver(PushDetails details,boolean shutdown){
  HTTPConnectObserver observer=pushes.getExactHostFor(details);
  if (observer != null && shutdown)   observer.shutdown();
}
Program: 4334
Project: 4334
Buggy source:
/** 
 * Registers a new ConnectObserver that is waiting for a socket from the given MRFD.
 * @param observer
 * @param mrfd
 */
void registerPushObserver(HTTPConnectObserver observer,MiniRemoteFileDesc mrfd){
  pushObservers.put(mrfd,observer);
}

Fixed version (ground truth):
/** 
 * Registers a new ConnectObserver that is waiting for a socket from the given MRFD.
 * @param observer
 * @param mrfd
 */
void registerPushObserver(HTTPConnectObserver observer,PushDetails details){
  pushes.addPushHost(details,observer);
}
Program: 4335
Project: 4335
Buggy source:
private void addYetToBeQueried(ContactNode node,int hop){
  if (!queried.contains(node) && !node.equals(context.getLocalNode())) {
    toQuery.put(node.getNodeID(),node);
    hopMap.put(node.getNodeID(),new Integer(hop));
  }
}

Fixed version (ground truth):
private void addYetToBeQueried(ContactNode node,int hop){
  if (!queried.contains(node.getNodeID()) && !node.equals(context.getLocalNode())) {
    toQuery.put(node.getNodeID(),node);
    hopMap.put(node.getNodeID(),new Integer(hop));
  }
}
Program: 4336
Project: 4336
Buggy source:
public void refreshBuckets(boolean force,BootstrapListener l) throws IOException {
  ArrayList bucketsLookups=new ArrayList();
  long now=System.currentTimeMillis();
  for (Iterator iter=bucketsTrie.values().iterator(); iter.hasNext(); ) {
    BucketNode bucket=(BucketNode)iter.next();
    long lastTouch=bucket.getTimeStamp();
    int length=Math.max(0,bucket.getDepth() - 1);
    List liveNodes=nodesTrie.range(bucket.getNodeID(),length,SELECT_ALIVE_CONTACTS);
    if (l != null && liveNodes.contains(context.getLocalNodeID())) {
      continue;
    }
    if (force || ((now - lastTouch) > RouteTableSettings.BUCKET_REFRESH_TIME.getValue()) || (bucket.getNodeCount() < K)|| (liveNodes.size() != bucket.getNodeCount())) {
      KUID randomID=KUID.createPrefxNodeID(bucket.getNodeID().getBytes(),bucket.getDepth());
      if (LOG.isTraceEnabled()) {
        LOG.trace("String_Node_Str" + bucket + "String_Node_Str"+ randomID);
      }
      bucketsLookups.add(randomID);
    }
  }
  if (bucketsLookups.isEmpty()) {
    if (l != null) {
      l.secondPhaseComplete(context.getLocalNodeID(),false,0L);
    }
  }
 else {
    BootstrapPhaseTwoManager listener=new BootstrapPhaseTwoManager(bucketsLookups,l);
    for (Iterator iter=bucketsLookups.iterator(); iter.hasNext(); ) {
      KUID lookupId=(KUID)iter.next();
      routingStats.BUCKET_REFRESH_COUNT.incrementStat();
      context.lookup(lookupId,listener);
    }
  }
}

Fixed version (ground truth):
public void refreshBuckets(boolean force,BootstrapListener l) throws IOException {
  ArrayList bucketsLookups=new ArrayList();
  long now=System.currentTimeMillis();
  for (Iterator iter=bucketsTrie.values().iterator(); iter.hasNext(); ) {
    BucketNode bucket=(BucketNode)iter.next();
    long lastTouch=bucket.getTimeStamp();
    int length=Math.max(0,bucket.getDepth() - 1);
    List liveNodes=nodesTrie.range(bucket.getNodeID(),length,SELECT_ALIVE_CONTACTS);
    if (l != null && liveNodes.contains(context.getLocalNode())) {
      continue;
    }
    if (force || ((now - lastTouch) > RouteTableSettings.BUCKET_REFRESH_TIME.getValue()) || (bucket.getNodeCount() < K)|| (liveNodes.size() != bucket.getNodeCount())) {
      KUID randomID=KUID.createPrefxNodeID(bucket.getNodeID().getBytes(),bucket.getDepth());
      if (LOG.isTraceEnabled()) {
        LOG.trace("String_Node_Str" + bucket + "String_Node_Str"+ randomID);
      }
      bucketsLookups.add(randomID);
    }
  }
  if (bucketsLookups.isEmpty()) {
    if (l != null) {
      l.secondPhaseComplete(context.getLocalNodeID(),false,0L);
    }
  }
 else {
    BootstrapPhaseTwoManager listener=new BootstrapPhaseTwoManager(bucketsLookups,l);
    for (Iterator iter=bucketsLookups.iterator(); iter.hasNext(); ) {
      KUID lookupId=(KUID)iter.next();
      routingStats.BUCKET_REFRESH_COUNT.incrementStat();
      context.lookup(lookupId,listener);
    }
  }
}
Program: 4337
Project: 4337
Buggy source:
public void foundNodes(KUID lookup,Collection nodes,Map queryKeys,long time){
  try {
    List keyValues=Arrays.asList(new KeyValue[]{keyValue});
    List targets=new ArrayList(nodes.size());
    for (Iterator it=nodes.iterator(); it.hasNext(); ) {
      ContactNode node=(ContactNode)it.next();
      QueryKey queryKey=(QueryKey)queryKeys.get(node);
      if (queryKey == null) {
        if (LOG.isErrorEnabled()) {
          LOG.error("String_Node_Str" + keyValues + "String_Node_Str"+ node+ "String_Node_Str");
        }
        continue;
      }
      store(node,queryKey,keyValues);
      targets.add(node);
    }
    if (l != null) {
      l.store(keyValues,targets);
    }
  }
 catch (  IOException err) {
    LOG.error(err);
  }
}

Fixed version (ground truth):
public void foundNodes(KUID lookup,Collection nodes,Map queryKeys,long time){
  try {
    List keyValues=Arrays.asList(new KeyValue[]{keyValue});
    List targets=new ArrayList(nodes.size());
    for (Iterator it=nodes.iterator(); it.hasNext(); ) {
      ContactNode node=(ContactNode)it.next();
      QueryKey queryKey=(QueryKey)queryKeys.get(node);
      if (node.getNodeID().equals(getLocalNodeID()))       continue;
      if (queryKey == null) {
        if (LOG.isErrorEnabled()) {
          LOG.error("String_Node_Str" + keyValues + "String_Node_Str"+ node+ "String_Node_Str");
        }
        continue;
      }
      store(node,queryKey,keyValues);
      targets.add(node);
    }
    if (l != null) {
      l.store(keyValues,targets);
    }
  }
 catch (  IOException err) {
    LOG.error(err);
  }
}
Program: 4338
Project: 4338
Buggy source:
public void lookup() throws IOException {
  MessageDispatcher messageDispatcher=context.getMessageDispatcher();
  if (LOG.isTraceEnabled()) {
    LOG.trace("String_Node_Str" + lookup);
  }
  int k=KademliaSettings.getReplicationParameter();
  List bucketList=context.getRouteTable().select(lookup,k,false,true);
  for (int i=bucketList.size() - 1; i >= 0; i--) {
    addYetToBeQueried((ContactNode)bucketList.get(i));
  }
  markAsQueried(context.getLocalNode());
  List alphaList=toQuery.select(lookup,KademliaSettings.getLookupParameter());
  for (int i=0; i < alphaList.size(); i++) {
    ContactNode node=(ContactNode)alphaList.get(i);
    if (LOG.isTraceEnabled()) {
      LOG.trace("String_Node_Str" + node + "String_Node_Str"+ lookup);
    }
    markAsQueried(node);
    ++activeSearches;
    messageDispatcher.send(node,createMessage(lookup),this);
  }
}

Fixed version (ground truth):
public void lookup() throws IOException {
  MessageDispatcher messageDispatcher=context.getMessageDispatcher();
  if (LOG.isTraceEnabled()) {
    LOG.trace("String_Node_Str" + lookup);
  }
  int k=KademliaSettings.getReplicationParameter();
  List bucketList=context.getRouteTable().select(lookup,k,false,true);
  for (int i=bucketList.size() - 1; i >= 0; i--) {
    addYetToBeQueried((ContactNode)bucketList.get(i));
  }
  markAsQueried(context.getLocalNode());
  addResponse(context.getLocalNode());
  List alphaList=toQuery.select(lookup,KademliaSettings.getLookupParameter());
  for (int i=0; i < alphaList.size(); i++) {
    ContactNode node=(ContactNode)alphaList.get(i);
    if (LOG.isTraceEnabled()) {
      LOG.trace("String_Node_Str" + node + "String_Node_Str"+ lookup);
    }
    markAsQueried(node);
    ++activeSearches;
    messageDispatcher.send(node,createMessage(lookup),this);
  }
}
Program: 4339
Project: 4339
Buggy source:
private void addResponse(ContactNode node){
  if (responses.size() == resultSize) {
    KUID furthest=lookup.invert();
    ContactNode worst=(ContactNode)responses.select(furthest);
    responses.remove(worst.getNodeID());
    queryKeys.remove(worst);
  }
  responses.put(node.getNodeID(),node);
}

Fixed version (ground truth):
private void addResponse(ContactNode node){
  responses.put(node.getNodeID(),node);
  if (responses.size() > resultSize) {
    KUID furthest=lookup.invert();
    ContactNode worst=(ContactNode)responses.select(furthest);
    responses.remove(worst.getNodeID());
    queryKeys.remove(worst);
  }
}
Program: 4341
Project: 4341
Buggy source:
public static String toString(Collection c){
  StringBuffer buffer=new StringBuffer();
  for (Iterator it=c.iterator(); it.hasNext(); ) {
    buffer.append(it.next()).append("String_Node_Str");
  }
  buffer.setLength(buffer.length() - 1);
  return buffer.toString();
}

Fixed version (ground truth):
public static String toString(Collection c){
  StringBuffer buffer=new StringBuffer();
  for (Iterator it=c.iterator(); it.hasNext(); ) {
    buffer.append(it.next()).append("String_Node_Str");
  }
  if (buffer.length() > 1)   buffer.setLength(buffer.length() - 1);
  return buffer.toString();
}
Program: 4342
Project: 4342
Buggy source:
/** 
 * Computes the closest address to targetID between this KUID and nodeID
 * @param nodeID the KUID to compare to
 * @param targetID the target ID
 * @return true if this is closer to targetID, false otherwise
 */
public boolean isCloser(KUID nodeID,KUID targetID){
  for (int i=0; i < id.length; i++) {
    int d1=(id[i] ^ targetID.id[i]) & 0xFF;
    int d2=(nodeID.id[i] ^ targetID.id[i]) & 0xFF;
    int diff=d1 - d2;
    if (diff < 0) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Computes the closest address to targetID between this KUID and nodeID
 * @param nodeID the KUID to compare to
 * @param targetID the target ID
 * @return true if this is closer to targetID, false otherwise
 */
public boolean isCloser(KUID nodeID,KUID targetID){
  for (int i=0; i < id.length; i++) {
    int dSelf=(id[i] ^ targetID.id[i]) & 0xFF;
    int dOther=(nodeID.id[i] ^ targetID.id[i]) & 0xFF;
    int diff=dOther - dSelf;
    if (diff > 0) {
      return true;
    }
 else     if (diff < 0) {
      return false;
    }
  }
  return false;
}
Program: 4343
Project: 4343
Buggy source:
protected void addResponse(ContactNode node){
  if (responses.size() == resultSize) {
    KUID furthest=lookup.invert();
    responses.remove((KUID)responses.select(furthest));
  }
  responses.put(node.getNodeID(),node);
}

Fixed version (ground truth):
protected void addResponse(ContactNode node){
  if (responses.size() == resultSize) {
    KUID furthest=lookup.invert();
    responses.remove(((ContactNode)responses.select(furthest)).getNodeID());
  }
  responses.put(node.getNodeID(),node);
}
Program: 4344
Project: 4344
Buggy source:
public int compare(Object a,Object b){
  return ((Thread)a).getName().compareTo(((Thread)b).getName());
}

Fixed version (ground truth):
public int compare(Object a,Object b){
  Thread threadA=(Thread)((Map.Entry)a).getKey();
  Thread threadB=(Thread)((Map.Entry)b).getKey();
  return threadA.getName().compareTo(threadB.getName());
}