Program: 5089
Project: 5089
Buggy source:
/** 
 * @modifies this
 * @effects returns a new outgoing, connected connection to somehost in this and removes it from this (atomically).  If manager is non-null,  it is (almost) guaranteed that we do not return any hosts we are connected to.   If no such host is found, blocks until a host is added.  If manager is non-null and this connection is no longer needed, returns null.  (Hack!) This method <i>is</i>  thread-safe, but it is cleverly synchronized so that multiple invocations can run  at the same time.  Note that an initial ping is no sent on the returned connection, nor is the connection added to manager.<p> Note: because this method interacts so tightly with ConnectionManager, it should probably be moved into ConnectionFetcher.run.  It is sufficient for HostCatcher to only provide the atomic chooseEndpoint method.
 */
public Connection choose(){
  while (true) {
    Endpoint e=null;
synchronized (this) {
      while (e == null) {
        if (manager != null && !manager.needsMoreConnections())         return null;
        try {
          e=getAnEndpoint();
        }
 catch (        NoSuchElementException exc) {
          try {
            this.wait(2000);
          }
 catch (          InterruptedException exc2) {
          }
        }
      }
    }
    if (manager != null && manager.isConnected(e))     continue;
    Connection ret=null;
    try {
      ret=new Connection(e.hostname,e.port);
      if (manager != null)       manager.tryingToConnect(ret,false);
      ret.connect();
      return ret;
    }
 catch (    IOException exc) {
      if (manager != null)       manager.failedToConnect(ret);
      continue;
    }
  }
}

Fixed version (ground truth):
/** 
 * @modifies this
 * @effects returns a new outgoing, connected connection to somehost in this and removes it from this (atomically).  If manager is non-null,  it is (almost) guaranteed that we do not return any hosts we are connected to.   If no such host is found, blocks until a host is added.  If manager is non-null and this connection is no longer needed, returns null.  (Hack!) This method <i>is</i>  thread-safe, but it is cleverly synchronized so that multiple invocations can run  at the same time.  Note that an initial ping is no sent on the returned connection, nor is the connection added to manager.<p> Note: because this method interacts so tightly with ConnectionManager, it should probably be moved into ConnectionFetcher.run.  It is sufficient for HostCatcher to only provide the atomic chooseEndpoint method.
 */
public Connection choose(){
  while (true) {
    Endpoint e=null;
synchronized (this) {
      while (e == null) {
        if (manager != null && !manager.needsMoreConnections())         return null;
        try {
          e=getAnEndpoint();
        }
 catch (        NoSuchElementException exc) {
          try {
            this.wait(2000);
          }
 catch (          InterruptedException exc2) {
          }
        }
      }
    }
    if (manager != null && manager.isConnected(e))     continue;
    Connection ret=null;
    try {
      ret=new Connection(e.hostname,e.port);
      if (manager != null) {
        manager.tryingToConnect(ret,false);
      }
      ret.connect();
      return ret;
    }
 catch (    IOException exc) {
      if (manager != null)       manager.failedToConnect(ret);
      continue;
    }
  }
}