Program: 153944
Project: 153944
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,SelectionKey.OP_READ);
    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);
    socket.register(selector,SelectionKey.OP_READ);
    getHandshake().init();
    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()) {
                SocketChannel channel=(SocketChannel)key.channel();
                channel.write(upstreamQueue.take());
              }
 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(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,SelectionKey.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);
    getHandshake().init();
    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));
}
}