Program: 10779
Project: 10779
Buggy source:
public synchronized void connectIfNecessary() throws IOException {
  if (((wsSession == null) || !wsSession.isOpen()) && !clientClose) {
    try {
      if (client == null) {
        client=new WebSocketClient();
        client.setConnectTimeout(this.connectionTimeout);
        client.start();
      }
 else {
        log.debug("String_Node_Str",label);
      }
      if (heartbeating) {
        enableHeartbeat();
      }
      Thread.sleep(100);
      SimpleEchoSocket socket=new SimpleEchoSocket();
      ClientUpgradeRequest request=new ClientUpgradeRequest();
      wsSession=client.connect(socket,new URI(url),request).get();
      wsSession.setIdleTimeout(this.idleTimeout);
    }
 catch (    Exception e) {
      if (connectionListener != null) {
        connectionListener.connectionFailed();
      }
      this.closeClient();
      throw new KurentoException(label + "String_Node_Str" + url,e);
    }
    try {
      if (!latch.await(this.connectionTimeout,TimeUnit.MILLISECONDS)) {
        if (connectionListener != null) {
          connectionListener.connectionFailed();
        }
        this.closeClient();
        throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
      }
      if (session == null) {
        session=new ClientSession(null,null,JsonRpcClientWebSocket.this);
        handlerManager.afterConnectionEstablished(session);
      }
 else {
        try {
          rsHelper.sendRequest(METHOD_RECONNECT,String.class);
          log.info("String_Node_Str",label,url);
        }
 catch (        JsonRpcErrorException e) {
          if (e.getCode() == 40007) {
            rsHelper.setSessionId(null);
            rsHelper.sendRequest(METHOD_RECONNECT,String.class);
            log.info("String_Node_Str",label,url);
          }
        }
      }
    }
 catch (    InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
}

Fixed version (ground truth):
public synchronized void connectIfNecessary() throws IOException {
  if (((wsSession == null) || !wsSession.isOpen()) && !clientClose) {
    try {
      if (client == null) {
        client=new WebSocketClient();
        client.setConnectTimeout(this.connectionTimeout);
        client.start();
      }
 else {
        log.debug("String_Node_Str",label);
      }
      if (heartbeating) {
        enableHeartbeat();
      }
      Thread.sleep(100);
      SimpleEchoSocket socket=new SimpleEchoSocket();
      ClientUpgradeRequest request=new ClientUpgradeRequest();
      wsSession=client.connect(socket,new URI(url),request).get(this.connectionTimeout,TimeUnit.MILLISECONDS);
      wsSession.setIdleTimeout(this.idleTimeout);
    }
 catch (    TimeoutException e) {
      if (connectionListener != null) {
        connectionListener.connectionFailed();
      }
      this.closeClient();
      throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
    }
catch (    Exception e) {
      if (connectionListener != null) {
        connectionListener.connectionFailed();
      }
      this.closeClient();
      throw new KurentoException(label + "String_Node_Str" + url,e);
    }
    try {
      if (!latch.await(this.connectionTimeout,TimeUnit.MILLISECONDS)) {
        if (connectionListener != null) {
          connectionListener.connectionFailed();
        }
        this.closeClient();
        throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
      }
      if (session == null) {
        session=new ClientSession(null,null,JsonRpcClientWebSocket.this);
        handlerManager.afterConnectionEstablished(session);
      }
 else {
        try {
          rsHelper.sendRequest(METHOD_RECONNECT,String.class);
          log.info("String_Node_Str",label,url);
        }
 catch (        JsonRpcErrorException e) {
          if (e.getCode() == 40007) {
            rsHelper.setSessionId(null);
            rsHelper.sendRequest(METHOD_RECONNECT,String.class);
            log.info("String_Node_Str",label,url);
          }
        }
      }
    }
 catch (    InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
}