Program: 10807
Project: 10807
Buggy source:
public synchronized void connectIfNecessary() throws IOException {
  if ((wsSession == null) || !wsSession.isOpen()) {
    try {
      client=new WebSocketClient();
      SimpleEchoSocket socket=new SimpleEchoSocket();
      client.start();
      ClientUpgradeRequest request=new ClientUpgradeRequest();
      Thread.sleep(100);
      wsSession=client.connect(socket,new URI(url),request).get();
    }
 catch (    Exception e) {
      if (connectionListener != null) {
        connectionListener.connectionFailed();
      }
      if (client != null) {
        log.debug("String_Node_Str",label);
        client.destroy();
        log.debug("String_Node_Str",label);
      }
      throw new KurentoException(label + "String_Node_Str" + url,e);
    }
    try {
      if (!latch.await(this.connectionTimeout,TimeUnit.MILLISECONDS)) {
        if (connectionListener != null) {
          connectionListener.connectionFailed();
        }
        if (client != null) {
          log.debug("String_Node_Str",label);
          client.destroy();
          log.debug("String_Node_Str",label);
        }
        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()) {
    try {
      client=new WebSocketClient();
      SimpleEchoSocket socket=new SimpleEchoSocket();
      client.start();
      ClientUpgradeRequest request=new ClientUpgradeRequest();
      Thread.sleep(100);
      wsSession=client.connect(socket,new URI(url),request).get();
    }
 catch (    Exception e) {
      if (connectionListener != null) {
        connectionListener.connectionFailed();
      }
      if (client != null) {
        log.debug("String_Node_Str",label);
        try {
          client.stop();
        }
 catch (        Exception e1) {
          log.debug("String_Node_Str",label);
        }
        client=null;
      }
      throw new KurentoException(label + "String_Node_Str" + url,e);
    }
    try {
      if (!latch.await(this.connectionTimeout,TimeUnit.MILLISECONDS)) {
        if (connectionListener != null) {
          connectionListener.connectionFailed();
        }
        if (client != null) {
          log.debug("String_Node_Str",label);
          try {
            client.stop();
          }
 catch (          Exception e1) {
            log.debug("String_Node_Str",label);
          }
          client=null;
        }
        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();
    }
  }
}