Program: 130595
Project: 130595
Buggy source:
public SOCKSProxy() throws IOException {
  OnionRouter guard=TorSocket.getConsensus().getRouterByName("String_Node_Str");
  TorSocket sock=new TorSocket(guard);
  TorCircuit circ=sock.createCircuit();
  circ.createRoute("String_Node_Str");
  circ.waitForState(TorCircuit.STATES.READY);
  System.out.println("String_Node_Str");
  ServerSocketChannel socks=ServerSocketChannel.open();
  socks.socket().bind(new InetSocketAddress(8000));
  socks.configureBlocking(false);
  Selector select=Selector.open();
  socks.register(select,SelectionKey.OP_ACCEPT);
  int lastClients=clients.size();
  while (true) {
    select.select(1000);
    Set keys=select.selectedKeys();
    Iterator iterator=keys.iterator();
    while (iterator.hasNext()) {
      SelectionKey k=(SelectionKey)iterator.next();
      if (!k.isValid())       continue;
      if (k.isAcceptable() && k.channel() == socks) {
        SocketChannel csock=socks.accept();
        if (csock == null)         continue;
        addClient(csock,circ);
        csock.register(select,SelectionKey.OP_READ);
      }
 else       if (k.isReadable()) {
        for (int i=0; i < clients.size(); i++) {
          SocksClient cl=clients.get(i);
          try {
            if (k.channel() == cl.client)             cl.newClientData(select,k);
          }
 catch (          IOException e) {
            cl.client.close();
            k.cancel();
            clients.remove(cl);
          }
        }
      }
    }
    for (int i=0; i < clients.size(); i++) {
      SocksClient cl=clients.get(i);
      if ((System.currentTimeMillis() - cl.lastData) > 30000L) {
        cl.stream.destroy();
        cl.client.close();
        clients.remove(cl);
      }
    }
    if (clients.size() != lastClients) {
      System.out.println(clients.size());
      lastClients=clients.size();
    }
  }
}

Fixed version (ground truth):
public SOCKSProxy() throws IOException {
  OnionRouter local=new OnionRouter("String_Node_Str","String_Node_Str","String_Node_Str",8001,0){
    @Override public PublicKey getPubKey() throws IOException {
      return TorCrypto.asn1GetPublicKey(Base64.decode("String_Node_Str" + "String_Node_Str" + "String_Node_Str"));
    }
  }
;
  OnionRouter guard=TorSocket.getConsensus().getRouterByName("String_Node_Str");
  TorSocket sock=new TorSocket(guard);
  TorCircuit circ=sock.createCircuit();
  circ.createRoute("String_Node_Str");
  circ.waitForState(TorCircuit.STATES.READY);
  System.out.println("String_Node_Str");
  ServerSocketChannel socks=ServerSocketChannel.open();
  socks.socket().bind(new InetSocketAddress(9050));
  socks.configureBlocking(false);
  Selector select=Selector.open();
  socks.register(select,SelectionKey.OP_ACCEPT);
  int lastClients=clients.size();
  while (true) {
    select.select(1000);
    Set keys=select.selectedKeys();
    Iterator iterator=keys.iterator();
    while (iterator.hasNext()) {
      SelectionKey k=(SelectionKey)iterator.next();
      if (!k.isValid())       continue;
      if (k.isAcceptable() && k.channel() == socks) {
        SocketChannel csock=socks.accept();
        if (csock == null)         continue;
        addClient(csock,circ);
        csock.register(select,SelectionKey.OP_READ);
      }
 else       if (k.isReadable()) {
        for (int i=0; i < clients.size(); i++) {
          SocksClient cl=clients.get(i);
          try {
            if (k.channel() == cl.client)             cl.newClientData(select,k);
          }
 catch (          IOException e) {
            cl.client.close();
            k.cancel();
            clients.remove(cl);
          }
        }
      }
    }
    for (int i=0; i < clients.size(); i++) {
      SocksClient cl=clients.get(i);
      if ((System.currentTimeMillis() - cl.lastData) > 30000L) {
        cl.stream.destroy();
        cl.client.close();
        clients.remove(cl);
      }
    }
    if (clients.size() != lastClients) {
      System.out.println(clients.size());
      lastClients=clients.size();
    }
  }
}