Program: 153924
Project: 153924
Buggy source:
public void connect() throws WebSocketException {
  try {
    if (!state.canTransitionTo(State.CONNECTED)) {
      throw new WebSocketException(3000,"String_Node_Str" + state);
    }
    URI proxyUri=new URI("String_Node_Str",null,location.getHost(),location.getPort(),null,null,null);
    List<Proxy> proxyList=ProxySelector.getDefault().select(proxyUri);
    proxyList.get(0).address();
    socket=SocketChannel.open();
    socket.configureBlocking(false);
    selector=Selector.open();
    socket.register(selector,OP_READ | OP_WRITE);
    long start=System.currentTimeMillis();
    if (socket.connect(endpoint)) {
      throw new WebSocketException(3000,"String_Node_Str");
    }
    while (!socket.finishConnect()) {
      if ((System.currentTimeMillis() - start) > connectionTimeout) {
        throw new WebSocketException(3004,"String_Node_Str");
      }
    }
    transitionTo(State.CONNECTED);
    pipeline.sendHandshakeUpstream(this,null);
    socket.write(upstreamQueue.take());
    transitionTo(State.HANDSHAKE);
    Runnable worker=new Runnable(){
      public void run(){
        try {
          while (!quit) {
            selector.select(connectionReadTimeout);
            for (            SelectionKey key : selector.selectedKeys()) {
              if (key.isValid() && key.isWritable() && upstreamQueue.peek() != null) {
                SocketChannel channel=(SocketChannel)key.channel();
                channel.write(upstreamQueue.poll());
              }
 else               if (key.isValid() && key.isReadable()) {
                read(socket,downstreamBuffer);
switch (state) {
case HANDSHAKE:
                  pipeline.sendHandshakeDownstream(WebSocketBase.this,downstreamBuffer);
                if (getHandshake().isDone()) {
                  if (downstreamBuffer.hasRemaining()) {
                    processBuffer(downstreamBuffer);
                  }
                }
              break;
case WAIT:
            processBuffer(downstreamBuffer);
          break;
case CLOSED:
        break;
    }
  }
}
}
}
 catch (WebSocketException we) {
handler.onError(WebSocketBase.this,we);
}
catch (Exception e) {
handler.onError(WebSocketBase.this,new WebSocketException(3000,e));
}
 finally {
try {
socket.close();
}
 catch (IOException e) {
;
}
try {
selector.close();
}
 catch (IOException e) {
;
}
}
}
}
;
quit=false;
if (blockingMode) {
worker.run();
}
 else {
ExecutorService executorService=Executors.newCachedThreadPool();
executorService.submit(worker);
}
}
 catch (WebSocketException we) {
handler.onError(this,we);
}
catch (Exception e) {
handler.onError(this,new WebSocketException(3100,e));
}
}

Fixed version (ground truth):
public void connect() throws WebSocketException {
  try {
    if (!state.canTransitionTo(State.CONNECTED)) {
      throw new WebSocketException(3040,"String_Node_Str" + state);
    }
    URI proxyUri=new URI("String_Node_Str",null,location.getHost(),location.getPort(),null,null,null);
    List<Proxy> proxyList=ProxySelector.getDefault().select(proxyUri);
    proxyList.get(0).address();
    socket=SocketChannel.open();
    socket.configureBlocking(false);
    selector=Selector.open();
    socket.register(selector,OP_READ | OP_WRITE);
    long start=System.currentTimeMillis();
    if (socket.connect(endpoint)) {
      throw new WebSocketException(3041,"String_Node_Str");
    }
    while (!socket.finishConnect()) {
      if ((System.currentTimeMillis() - start) > connectionTimeout) {
        throw new WebSocketException(3042,"String_Node_Str");
      }
    }
    transitionTo(State.CONNECTED);
    pipeline.sendHandshakeUpstream(this,null);
    socket.write(upstreamQueue.take());
    transitionTo(State.HANDSHAKE);
    Runnable worker=new Runnable(){
      public void run(){
        try {
          while (!quit) {
            selector.select(connectionReadTimeout);
            for (            SelectionKey key : selector.selectedKeys()) {
              if (key.isValid() && key.isWritable() && upstreamQueue.peek() != null) {
                SocketChannel channel=(SocketChannel)key.channel();
                channel.write(upstreamQueue.poll());
              }
 else               if (key.isValid() && key.isReadable()) {
                read(socket,downstreamBuffer);
switch (state) {
case HANDSHAKE:
                  pipeline.sendHandshakeDownstream(WebSocketBase.this,downstreamBuffer);
                if (getHandshake().isDone()) {
                  if (downstreamBuffer.hasRemaining()) {
                    processBuffer(downstreamBuffer);
                  }
                }
              break;
case WAIT:
            processBuffer(downstreamBuffer);
          break;
case CLOSED:
        break;
    }
  }
}
}
}
 catch (WebSocketException we) {
handler.onError(WebSocketBase.this,we);
}
catch (Exception e) {
handler.onError(WebSocketBase.this,new WebSocketException(3043,e));
}
 finally {
try {
socket.close();
}
 catch (IOException e) {
;
}
try {
selector.close();
}
 catch (IOException e) {
;
}
}
}
}
;
quit=false;
if (blockingMode) {
worker.run();
}
 else {
ExecutorService executorService=Executors.newCachedThreadPool();
executorService.submit(worker);
}
}
 catch (WebSocketException we) {
handler.onError(this,we);
}
catch (Exception e) {
handler.onError(this,new WebSocketException(3044,e));
}
}