Program: 4340
Project: 4340
Buggy source:
private void lookupStep() throws IOException {
  if (toQuery.isEmpty() && activeSearches == 0) {
    if (LOG.isTraceEnabled()) {
      LOG.trace("String_Node_Str" + lookup + "String_Node_Str");
    }
    if (isValueLookup()) {
      finishValueLookup(lookup,null,time);
    }
 else {
      List nodes=responses.select(lookup,responses.size());
      finishNodeLookup(lookup,nodes,queryKeys,time);
    }
    finished=true;
    return;
  }
  if (responses.size() == resultSize) {
    KUID furthest=lookup.invert();
    ContactNode worstResponse=(ContactNode)responses.select(furthest);
    ContactNode bestToQuery=(ContactNode)toQuery.select(lookup);
    if (bestToQuery == null || worstResponse.getNodeID().isCloser(bestToQuery.getNodeID(),lookup)) {
      ContactNode bestResponse=(ContactNode)responses.select(lookup);
      if (LOG.isTraceEnabled()) {
        LOG.trace("String_Node_Str" + lookup + "String_Node_Str"+ bestResponse+ "String_Node_Str"+ queried.size()+ "String_Node_Str");
      }
      if (isValueLookup()) {
        finishValueLookup(lookup,null,time);
      }
 else {
        List nodes=responses.select(lookup,responses.size());
        finishNodeLookup(lookup,nodes,queryKeys,time);
      }
      finished=true;
      return;
    }
  }
  int numLookups=KademliaSettings.getLookupParameter() - activeSearches;
  if (numLookups > 0) {
    List bucketList=toQuery.select(lookup,numLookups);
    final int size=bucketList.size();
    MessageDispatcher messageDispatcher=context.getMessageDispatcher();
    for (int i=0; i < size; i++) {
      ContactNode node=(ContactNode)bucketList.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):
private void lookupStep() throws IOException {
  if (toQuery.isEmpty() && activeSearches == 0) {
    if (LOG.isTraceEnabled()) {
      LOG.trace("String_Node_Str" + lookup + "String_Node_Str");
    }
    if (isValueLookup()) {
      finishValueLookup(lookup,null,time);
    }
 else {
      List nodes=responses.select(lookup,responses.size());
      finishNodeLookup(lookup,nodes,queryKeys,time);
    }
    finished=true;
    return;
  }
  if ((responses.size() == resultSize) && (activeSearches == 0)) {
    KUID furthest=lookup.invert();
    ContactNode worstResponse=(ContactNode)responses.select(furthest);
    ContactNode bestToQuery=(ContactNode)toQuery.select(lookup);
    if (bestToQuery == null || worstResponse.getNodeID().isCloser(bestToQuery.getNodeID(),lookup)) {
      ContactNode bestResponse=(ContactNode)responses.select(lookup);
      if (LOG.isTraceEnabled()) {
        LOG.trace("String_Node_Str" + lookup + "String_Node_Str"+ bestResponse+ "String_Node_Str"+ queried.size()+ "String_Node_Str");
      }
      if (isValueLookup()) {
        finishValueLookup(lookup,null,time);
      }
 else {
        List nodes=responses.select(lookup,responses.size());
        finishNodeLookup(lookup,nodes,queryKeys,time);
      }
      finished=true;
      return;
    }
  }
  int numLookups=KademliaSettings.getLookupParameter() - activeSearches;
  if (numLookups > 0) {
    List bucketList=toQuery.select(lookup,numLookups);
    final int size=bucketList.size();
    MessageDispatcher messageDispatcher=context.getMessageDispatcher();
    for (int i=0; i < size; i++) {
      ContactNode node=(ContactNode)bucketList.get(i);
      if (LOG.isTraceEnabled()) {
        LOG.trace("String_Node_Str" + node + "String_Node_Str"+ lookup);
      }
      markAsQueried(node);
      ++activeSearches;
      messageDispatcher.send(node,createMessage(lookup),this);
    }
  }
}