Program: 85868
Project: 85868
Buggy source:
/** 
 * Returns a list of peers that were found in the IRC channel. Note that just because a peer appears in the list does not mean it is accepting connections. The given time out value is applied for every IP returned by DNS for the given server, so a timeout value of 1 second may result in 5 seconds delay if 5 servers are advertised.
 */
public InetSocketAddress[] getPeers(long timeoutValue,TimeUnit timeoutUnit) throws PeerDiscoveryException {
  ArrayList<InetSocketAddress> addresses=new ArrayList<InetSocketAddress>();
  connection=null;
  BufferedReader reader=null;
  try {
    InetAddress[] ips=InetAddress.getAllByName(server);
    int ipCursorStart=(int)(Math.random() * ips.length);
    int ipCursor=ipCursorStart;
    do {
      connection=new Socket();
      try {
        InetAddress ip=ips[ipCursor];
        long timeoutMsec=TimeUnit.MILLISECONDS.convert(timeoutValue,timeoutUnit);
        log.info("String_Node_Str" + ip);
        connection.connect(new InetSocketAddress(ip,port),(int)timeoutMsec);
      }
 catch (      SocketTimeoutException e) {
        connection=null;
      }
catch (      IOException e) {
        connection=null;
      }
      ipCursor=(ipCursor + 1) % ips.length;
      if (ipCursor == ipCursorStart) {
        throw new PeerDiscoveryException("String_Node_Str" + server);
      }
    }
 while (connection == null);
    writer=new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(),"String_Node_Str"));
    reader=new BufferedReader(new InputStreamReader(connection.getInputStream(),"String_Node_Str"));
    String nickRnd=String.format("String_Node_Str",new Random().nextInt(Integer.MAX_VALUE));
    String command="String_Node_Str" + nickRnd;
    logAndSend(command);
    command="String_Node_Str" + nickRnd + "String_Node_Str"+ nickRnd;
    logAndSend(command);
    writer.flush();
    String currLine;
    while ((currLine=reader.readLine()) != null) {
      onIRCReceive(currLine);
      if (checkLineStatus("String_Node_Str",currLine)) {
        break;
      }
    }
    logAndSend("String_Node_Str" + channel);
    logAndSend("String_Node_Str" + channel);
    writer.flush();
    while ((currLine=reader.readLine()) != null) {
      onIRCReceive(currLine);
      if (checkLineStatus("String_Node_Str",currLine)) {
        int subIndex=0;
        if (currLine.startsWith("String_Node_Str")) {
          subIndex=1;
        }
        String spacedList=currLine.substring(currLine.indexOf("String_Node_Str",subIndex));
        addresses.addAll(parseUserList(spacedList.substring(1).split("String_Node_Str")));
      }
 else       if (checkLineStatus("String_Node_Str",currLine)) {
        break;
      }
    }
    logAndSend("String_Node_Str" + channel);
    logAndSend("String_Node_Str");
    writer.flush();
  }
 catch (  Exception e) {
    throw new PeerDiscoveryException(e.getMessage(),e);
  }
 finally {
    try {
      if (reader != null)       reader.close();
      if (writer != null)       writer.close();
      if (connection != null)       connection.close();
    }
 catch (    IOException e) {
      log.warn("String_Node_Str" + e.toString());
    }
  }
  return addresses.toArray(new InetSocketAddress[]{});
}

Fixed version (ground truth):
/** 
 * Returns a list of peers that were found in the IRC channel. Note that just because a peer appears in the list does not mean it is accepting connections. The given time out value is applied for every IP returned by DNS for the given server, so a timeout value of 1 second may result in 5 seconds delay if 5 servers are advertised.
 */
public InetSocketAddress[] getPeers(long timeoutValue,TimeUnit timeoutUnit) throws PeerDiscoveryException {
  ArrayList<InetSocketAddress> addresses=new ArrayList<InetSocketAddress>();
  connection=null;
  BufferedReader reader=null;
  try {
    InetAddress[] ips=InetAddress.getAllByName(server);
    int ipCursorStart=(int)(Math.random() * ips.length);
    int ipCursor=ipCursorStart;
    do {
      connection=new Socket();
      int timeoutMsec=(int)TimeUnit.MILLISECONDS.convert(timeoutValue,timeoutUnit);
      connection.setSoTimeout(timeoutMsec);
      try {
        InetAddress ip=ips[ipCursor];
        log.info("String_Node_Str" + ip);
        connection.connect(new InetSocketAddress(ip,port),timeoutMsec);
      }
 catch (      SocketTimeoutException e) {
        connection=null;
      }
catch (      IOException e) {
        connection=null;
      }
      ipCursor=(ipCursor + 1) % ips.length;
      if (ipCursor == ipCursorStart) {
        throw new PeerDiscoveryException("String_Node_Str" + server);
      }
    }
 while (connection == null);
    writer=new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(),"String_Node_Str"));
    reader=new BufferedReader(new InputStreamReader(connection.getInputStream(),"String_Node_Str"));
    String nickRnd=String.format("String_Node_Str",new Random().nextInt(Integer.MAX_VALUE));
    String command="String_Node_Str" + nickRnd;
    logAndSend(command);
    command="String_Node_Str" + nickRnd + "String_Node_Str"+ nickRnd;
    logAndSend(command);
    writer.flush();
    String currLine;
    while ((currLine=reader.readLine()) != null) {
      onIRCReceive(currLine);
      if (checkLineStatus("String_Node_Str",currLine)) {
        break;
      }
    }
    logAndSend("String_Node_Str" + channel);
    logAndSend("String_Node_Str" + channel);
    writer.flush();
    while ((currLine=reader.readLine()) != null) {
      onIRCReceive(currLine);
      if (checkLineStatus("String_Node_Str",currLine)) {
        int subIndex=0;
        if (currLine.startsWith("String_Node_Str")) {
          subIndex=1;
        }
        String spacedList=currLine.substring(currLine.indexOf("String_Node_Str",subIndex));
        addresses.addAll(parseUserList(spacedList.substring(1).split("String_Node_Str")));
      }
 else       if (checkLineStatus("String_Node_Str",currLine)) {
        break;
      }
    }
    logAndSend("String_Node_Str" + channel);
    logAndSend("String_Node_Str");
    writer.flush();
  }
 catch (  Exception e) {
    throw new PeerDiscoveryException(e.getMessage(),e);
  }
 finally {
    try {
      if (reader != null)       reader.close();
      if (writer != null)       writer.close();
      if (connection != null)       connection.close();
    }
 catch (    IOException e) {
      log.warn("String_Node_Str" + e.toString());
    }
  }
  return addresses.toArray(new InetSocketAddress[]{});
}