Program: 10785
Project: 10785
Buggy source:
public synchronized void connectIfNecessary() throws IOException {
  if ((wsSession == null) || !wsSession.isOpen()) {
    try {
      if (client == null) {
        client=new WebSocketClient();
        client.setConnectTimeout(this.connectionTimeout);
        client.start();
      }
 else {
        log.debug("String_Node_Str",label);
      }
      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();
      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();
    }
  }
}