Program: 4590
Project: 4590
Buggy source:
/** 
 * @param connectCode 0 means no connection, 1 means connection queued, 2means connection made, 3 means no connection required, 4 means partial range available
 * @param queuePos the position of this downloader in the remote queue, MUSTbe equal to -1 unless connectCode == 1  <P> Interrupts a remotely queued thread if the value of connectCode is 2 (meaning queuePos is -1) or connectCode is 1(meaning queuePos is the the remote position of this thread) AND a thread has a worse position than queuePos.  
 * @return true if there is no need to kill any threads, or if thecurrentThread is already in the queuedThreads, or if we did kill a thread worse than this thread. 
 */
private boolean killQueuedIfNecessary(int connectCode,int queuePos){
  Assert.that(connectCode >= 0 && connectCode <= 4,"String_Node_Str");
  if (connectCode == 2)   Assert.that(queuePos == -1,"String_Node_Str");
  if (queuePos > -1)   Assert.that(connectCode == 1,"String_Node_Str");
  if (connectCode == 0)   return false;
  if (connectCode == 3)   return false;
  if (connectCode == 4)   return false;
  Thread killThread=null;
synchronized (this) {
    if (getNumDownloaders() < getSwarmCapacity())     return true;
    if (queuedThreads.containsKey(Thread.currentThread()))     return true;
    Iterator iter=queuedThreads.keySet().iterator();
    while (iter.hasNext()) {
      Object o=iter.next();
      int currQueue=((Integer)queuedThreads.get(o)).intValue();
      if (currQueue > queuePos)       killThread=(Thread)o;
    }
    if (killThread == null)     return false;
    killThread.interrupt();
    if (connectCode == 1)     queuedThreads.put(Thread.currentThread(),new Integer(queuePos));
    return true;
  }
}

Fixed version (ground truth):
/** 
 * @param connectCode 0 means no connection, 1 means connection queued, 2means connection made, 3 means no connection required, 4 means partial range available
 * @param queuePos the position of this downloader in the remote queue, MUSTbe equal to -1 unless connectCode == 1  <P> Interrupts a remotely queued thread if the value of connectCode is 2 (meaning queuePos is -1) or connectCode is 1(meaning queuePos is the the remote position of this thread) AND a thread has a worse position than queuePos.  
 * @return true if this thread should be kept around, false otherwise --explicitly, there is no need to kill any threads, or if the currentThread is already in the queuedThreads, or if we did kill a thread worse than this thread.  
 */
private boolean killQueuedIfNecessary(int connectCode,int queuePos){
  Assert.that(connectCode >= 0 && connectCode <= 4,"String_Node_Str");
  if (connectCode == 2)   Assert.that(queuePos == -1,"String_Node_Str");
  if (queuePos > -1)   Assert.that(connectCode == 1,"String_Node_Str");
  if (connectCode == 0)   return false;
  if (connectCode == 3)   return false;
  if (connectCode == 4)   return false;
  Thread killThread=null;
  Thread currentThread=Thread.currentThread();
synchronized (this) {
    if (getNumDownloaders() < getSwarmCapacity()) {
      if (connectCode == 1)       queuedThreads.put(currentThread,new Integer(queuePos));
      return true;
    }
    if (queuedThreads.containsKey(currentThread)) {
      if (connectCode == 1)       queuedThreads.put(currentThread,new Integer(queuePos));
      return true;
    }
    Iterator iter=queuedThreads.keySet().iterator();
    while (iter.hasNext()) {
      Object o=iter.next();
      int currQueue=((Integer)queuedThreads.get(o)).intValue();
      if (currQueue > queuePos)       killThread=(Thread)o;
    }
    if (killThread == null)     return false;
    killThread.interrupt();
    if (connectCode == 1)     queuedThreads.put(currentThread,new Integer(queuePos));
    return true;
  }
}