Program: 62593
Project: 62593
Buggy source:
/** 
 * Connects to a Harmony Hub using credentials obtained through network discovery x
 */
private void connectToHub(){
  final String host=getThing().getProperties().get(HarmonyHubBindingConstants.HUB_PROPERTY_HOST);
  final String accountId=getThing().getProperties().get(HarmonyHubBindingConstants.HUB_PROPERTY_ACCOUNTID);
  final String sessionId=getThing().getProperties().get(HarmonyHubBindingConstants.HUB_PROPERTY_SESSIONID);
  if (host == null || accountId == null || sessionId == null) {
    logger.error("String_Node_Str",host,accountId,sessionId);
    return;
  }
  client=HarmonyClient.getInstance();
  client.addListener(new HarmonyHubListener(){
    @Override public void removeFrom(    HarmonyClient hc){
    }
    @Override public void addTo(    HarmonyClient hc){
      hc.addListener(new ActivityChangeListener(){
        @Override public void activityStarted(        Activity activity){
          updateState(activity);
        }
      }
);
    }
  }
);
  try {
    logger.debug("String_Node_Str",host,sessionId,accountId);
    client.connect(host,new LoginToken(accountId,sessionId));
    heartBeatJob=scheduler.scheduleAtFixedRate(new Runnable(){
      @Override public void run(){
        try {
          client.sendPing();
        }
 catch (        Exception e) {
          logger.error("String_Node_Str" + host,e);
          setOfflineAndReconnect();
        }
      }
    }
,heartBeatInterval,heartBeatInterval,TimeUnit.SECONDS);
    updateStatus(ThingStatus.ONLINE);
    buildChannel();
  }
 catch (  Exception e) {
    logger.error("String_Node_Str" + host,e);
    setOfflineAndReconnect();
  }
}

Fixed version (ground truth):
/** 
 * Connects to a Harmony Hub using credentials obtained through network discovery x
 */
private synchronized void connectToHub(){
  disconnectFromHub();
  final String host=getThing().getProperties().get(HarmonyHubBindingConstants.HUB_PROPERTY_HOST);
  final String accountId=getThing().getProperties().get(HarmonyHubBindingConstants.HUB_PROPERTY_ACCOUNTID);
  final String sessionId=getThing().getProperties().get(HarmonyHubBindingConstants.HUB_PROPERTY_SESSIONID);
  if (host == null || accountId == null || sessionId == null) {
    logger.error("String_Node_Str",host,accountId,sessionId);
    return;
  }
  client=HarmonyClient.getInstance();
  client.addListener(new HarmonyHubListener(){
    @Override public void removeFrom(    HarmonyClient hc){
    }
    @Override public void addTo(    HarmonyClient hc){
      hc.addListener(new ActivityChangeListener(){
        @Override public void activityStarted(        Activity activity){
          updateState(activity);
        }
      }
);
    }
  }
);
  try {
    logger.debug("String_Node_Str",host,sessionId,accountId);
    client.connect(host,new LoginToken(accountId,sessionId));
    heartBeatJob=scheduler.scheduleAtFixedRate(new Runnable(){
      @Override public void run(){
        try {
          client.sendPing();
        }
 catch (        Exception e) {
          logger.error("String_Node_Str" + host,e);
          setOfflineAndReconnect();
        }
      }
    }
,heartBeatInterval,heartBeatInterval,TimeUnit.SECONDS);
    updateStatus(ThingStatus.ONLINE);
    buildChannel();
  }
 catch (  Exception e) {
    logger.error("String_Node_Str" + host,e);
    setOfflineAndReconnect();
  }
}