Program: 130741
Project: 130741
Buggy source:
/** 
 * Waits for a synchronization message from peer.
 * @param peer the id of the expected peer that synchronization message willcome from.
 * @throws InterruptedException in case of interruption.
 * @throws TimeoutException in case of timeout.
 * @throws IOException in case of IO failure.
 */
protected void waitForSync(String peer) throws InterruptedException, TimeoutException, IOException {
  LOG.debug("String_Node_Str",peer);
  Log log=this.persistence.getLog();
  Zxid lastZxid=log.getLatestZxid();
  Zxid lastZxidPeer=null;
  Message msg=null;
  String source=null;
  while (true) {
    MessageTuple tuple=getMessage(getSyncTimeoutMs());
    source=tuple.getServerId();
    msg=tuple.getMessage();
    if ((msg.getType() != MessageType.DIFF && msg.getType() != MessageType.TRUNCATE && msg.getType() != MessageType.SNAPSHOT && msg.getType() != MessageType.PULL_TXN_REQ) || !source.equals(peer)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg),source);
      }
      continue;
    }
 else {
      break;
    }
  }
  if (msg.getType() == MessageType.PULL_TXN_REQ) {
    LOG.debug("String_Node_Str",source);
    ZabMessage.Zxid z=msg.getPullTxnReq().getLastZxid();
    lastZxidPeer=MessageBuilder.fromProtoZxid(z);
    SyncPeerTask syncTask=new SyncPeerTask(source,lastZxidPeer,lastZxid,this.persistence.getLastSeenConfig());
    syncTask.run();
    MessageTuple tuple=getExpectedMessage(MessageType.DIFF,peer,getSyncTimeoutMs());
    msg=tuple.getMessage();
    ZabMessage.Diff diff=msg.getDiff();
    lastZxidPeer=MessageBuilder.fromProtoZxid(diff.getLastZxid());
    if (lastZxidPeer.compareTo(lastZxid) != 0) {
      LOG.error("String_Node_Str");
      throw new RuntimeException("String_Node_Str" + "String_Node_Str");
    }
    waitForSyncEnd(peer);
    return;
  }
  if (msg.getType() == MessageType.DIFF) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg));
    }
    ZabMessage.Diff diff=msg.getDiff();
    lastZxidPeer=MessageBuilder.fromProtoZxid(diff.getLastZxid());
    if (lastZxid.compareTo(lastZxidPeer) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
 else   if (msg.getType() == MessageType.TRUNCATE) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg));
    }
    ZabMessage.Truncate trunc=msg.getTruncate();
    Zxid lastPrefixZxid=MessageBuilder.fromProtoZxid(trunc.getLastPrefixZxid());
    lastZxidPeer=MessageBuilder.fromProtoZxid(trunc.getLastZxid());
    log.truncate(lastPrefixZxid);
    if (lastZxidPeer.compareTo(lastPrefixZxid) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
 else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg));
    }
    ZabMessage.Snapshot snap=msg.getSnapshot();
    lastZxidPeer=MessageBuilder.fromProtoZxid(snap.getLastZxid());
    Zxid snapZxid=MessageBuilder.fromProtoZxid(snap.getSnapZxid());
    msg=getExpectedMessage(MessageType.FILE_RECEIVED,peer).getMessage();
    File file=new File(msg.getFileReceived().getFullPath());
    persistence.setSnapshotFile(file,snapZxid);
    log.truncate(Zxid.ZXID_NOT_EXIST);
    if (lastZxidPeer.compareTo(Zxid.ZXID_NOT_EXIST) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
  while (true) {
    MessageTuple tuple=getExpectedMessage(MessageType.PROPOSAL,peer,getSyncTimeoutMs());
    msg=tuple.getMessage();
    source=tuple.getServerId();
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg),source);
    }
    ZabMessage.Proposal prop=msg.getProposal();
    Zxid zxid=MessageBuilder.fromProtoZxid(prop.getZxid());
    log.append(MessageBuilder.fromProposal(prop));
    if (zxid.compareTo(lastZxidPeer) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
}

Fixed version (ground truth):
/** 
 * Waits for a synchronization message from peer.
 * @param peer the id of the expected peer that synchronization message willcome from.
 * @throws InterruptedException in case of interruption.
 * @throws TimeoutException in case of timeout.
 * @throws IOException in case of IO failure.
 */
protected void waitForSync(String peer) throws InterruptedException, TimeoutException, IOException {
  LOG.debug("String_Node_Str",peer);
  Log log=this.persistence.getLog();
  Zxid lastZxid=log.getLatestZxid();
  Zxid lastZxidPeer=null;
  Message msg=null;
  String source=null;
  while (true) {
    MessageTuple tuple=getMessage(getSyncTimeoutMs());
    source=tuple.getServerId();
    msg=tuple.getMessage();
    if ((msg.getType() != MessageType.DIFF && msg.getType() != MessageType.TRUNCATE && msg.getType() != MessageType.SNAPSHOT && msg.getType() != MessageType.PULL_TXN_REQ) || !source.equals(peer)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg),source);
      }
      continue;
    }
 else {
      break;
    }
  }
  if (msg.getType() == MessageType.PULL_TXN_REQ) {
    LOG.debug("String_Node_Str",source);
    ZabMessage.Zxid z=msg.getPullTxnReq().getLastZxid();
    lastZxidPeer=MessageBuilder.fromProtoZxid(z);
    SyncPeerTask syncTask=new SyncPeerTask(source,lastZxidPeer,lastZxid,this.persistence.getLastSeenConfig());
    syncTask.run();
    MessageTuple tuple=getExpectedMessage(MessageType.DIFF,peer,getSyncTimeoutMs());
    msg=tuple.getMessage();
    ZabMessage.Diff diff=msg.getDiff();
    lastZxidPeer=MessageBuilder.fromProtoZxid(diff.getLastZxid());
    if (lastZxidPeer.compareTo(lastZxid) != 0) {
      LOG.error("String_Node_Str");
      throw new RuntimeException("String_Node_Str" + "String_Node_Str");
    }
    waitForSyncEnd(peer);
    return;
  }
  if (msg.getType() == MessageType.DIFF) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg));
    }
    ZabMessage.Diff diff=msg.getDiff();
    lastZxidPeer=MessageBuilder.fromProtoZxid(diff.getLastZxid());
    if (lastZxid.compareTo(lastZxidPeer) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
 else   if (msg.getType() == MessageType.TRUNCATE) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg));
    }
    ZabMessage.Truncate trunc=msg.getTruncate();
    Zxid lastPrefixZxid=MessageBuilder.fromProtoZxid(trunc.getLastPrefixZxid());
    lastZxidPeer=MessageBuilder.fromProtoZxid(trunc.getLastZxid());
    log.truncate(lastPrefixZxid);
    if (lastZxidPeer.compareTo(lastPrefixZxid) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
 else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg));
    }
    ZabMessage.Snapshot snap=msg.getSnapshot();
    lastZxidPeer=MessageBuilder.fromProtoZxid(snap.getLastZxid());
    Zxid snapZxid=MessageBuilder.fromProtoZxid(snap.getSnapZxid());
    msg=getExpectedMessage(MessageType.FILE_RECEIVED,peer).getMessage();
    File file=new File(msg.getFileReceived().getFullPath());
    persistence.setSnapshotFile(file,snapZxid);
    log.truncate(Zxid.ZXID_NOT_EXIST);
    if (lastZxidPeer.compareTo(snapZxid) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
  while (true) {
    MessageTuple tuple=getExpectedMessage(MessageType.PROPOSAL,peer,getSyncTimeoutMs());
    msg=tuple.getMessage();
    source=tuple.getServerId();
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str",TextFormat.shortDebugString(msg),source);
    }
    ZabMessage.Proposal prop=msg.getProposal();
    Zxid zxid=MessageBuilder.fromProtoZxid(prop.getZxid());
    log.append(MessageBuilder.fromProposal(prop));
    if (zxid.compareTo(lastZxidPeer) == 0) {
      waitForSyncEnd(peer);
      return;
    }
  }
}