Program: 130734
Project: 130734
Buggy source:
/** 
 * Starts from joining some one who is in cluster..
 * @param peer the id of server who is in cluster.
 * @throws Exception in case something goes wrong.
 */
@Override public void join(String peer) throws Exception {
  LOG.debug("String_Node_Str");
  try {
    LOG.debug("String_Node_Str",peer);
    Message query=MessageBuilder.buildQueryLeader();
    MessageTuple tuple=null;
    while (true) {
      try {
        sendMessage(peer,query);
        tuple=getExpectedMessage(MessageType.QUERY_LEADER_REPLY,peer);
        break;
      }
 catch (      TimeoutException ex) {
        int retryInterval=1;
        LOG.warn("String_Node_Str" + "String_Node_Str",retryInterval);
        Thread.sleep(retryInterval * 1000);
      }
    }
    this.electedLeader=tuple.getMessage().getReply().getLeader();
    LOG.debug("String_Node_Str",this.electedLeader);
    while (true) {
      try {
        joinSynchronization();
        break;
      }
 catch (      TimeoutException|BackToElectionException ex) {
        LOG.debug("String_Node_Str",getSyncTimeoutMs(),persistence.getLog().getLatestZxid());
        transport.clear(electedLeader);
        clearMessageQueue();
      }
    }
    restoreFromSnapshot();
    deliverUndeliveredTxns();
    changePhase(Phase.BROADCASTING);
    accepting();
  }
 catch (  InterruptedException e) {
    LOG.debug("String_Node_Str");
    throw e;
  }
catch (  TimeoutException e) {
    LOG.debug("String_Node_Str" + "String_Node_Str",this.electedLeader,this.config.getTimeoutMs());
    if (persistence.getLastSeenConfig() == null) {
      throw new JoinFailure("String_Node_Str");
    }
  }
catch (  BackToElectionException e) {
    LOG.debug("String_Node_Str");
    if (persistence.getLastSeenConfig() == null) {
      throw new JoinFailure("String_Node_Str");
    }
  }
catch (  LeftCluster e) {
    LOG.debug("String_Node_Str",e.getMessage());
    throw e;
  }
catch (  Exception e) {
    LOG.error("String_Node_Str",e);
    throw e;
  }
 finally {
    if (this.electedLeader != null) {
      this.transport.clear(this.electedLeader);
    }
    clearMessageQueue();
  }
}

Fixed version (ground truth):
/** 
 * Starts from joining some one who is in cluster..
 * @param peer the id of server who is in cluster.
 * @throws Exception in case something goes wrong.
 */
@Override public void join(String peer) throws Exception {
  LOG.debug("String_Node_Str");
  try {
    LOG.debug("String_Node_Str",peer);
    Message query=MessageBuilder.buildQueryLeader();
    MessageTuple tuple=null;
    while (true) {
      try {
        sendMessage(peer,query);
        tuple=getExpectedMessage(MessageType.QUERY_LEADER_REPLY,peer);
        break;
      }
 catch (      TimeoutException ex) {
        long retryInterval=1;
        LOG.warn("String_Node_Str" + "String_Node_Str",retryInterval);
        Thread.sleep(retryInterval * 1000);
      }
    }
    this.electedLeader=tuple.getMessage().getReply().getLeader();
    LOG.debug("String_Node_Str",this.electedLeader);
    while (true) {
      try {
        joinSynchronization();
        break;
      }
 catch (      TimeoutException|BackToElectionException ex) {
        LOG.debug("String_Node_Str",getSyncTimeoutMs(),persistence.getLog().getLatestZxid());
        transport.clear(electedLeader);
        clearMessageQueue();
      }
    }
    restoreFromSnapshot();
    deliverUndeliveredTxns();
    changePhase(Phase.BROADCASTING);
    accepting();
  }
 catch (  InterruptedException e) {
    LOG.debug("String_Node_Str");
    throw e;
  }
catch (  TimeoutException e) {
    LOG.debug("String_Node_Str" + "String_Node_Str",this.electedLeader,this.config.getTimeoutMs());
    if (persistence.getLastSeenConfig() == null) {
      throw new JoinFailure("String_Node_Str");
    }
  }
catch (  BackToElectionException e) {
    LOG.debug("String_Node_Str");
    if (persistence.getLastSeenConfig() == null) {
      throw new JoinFailure("String_Node_Str");
    }
  }
catch (  LeftCluster e) {
    LOG.debug("String_Node_Str",e.getMessage());
    throw e;
  }
catch (  Exception e) {
    LOG.error("String_Node_Str",e);
    throw e;
  }
 finally {
    if (this.electedLeader != null) {
      this.transport.clear(this.electedLeader);
    }
    clearMessageQueue();
  }
}