Program: 60839
Project: 60839
Buggy source:
/** 
 * Block until becoming the active master. Method blocks until there is not another active master and our attempt to become the new active master is successful. This also makes sure that we are watching the master znode so will be notified if another master dies.
 * @param checkInterval the interval to check if the master is stopped
 * @param startupStatus the monitor status to track the progress
 * @return True if no issue becoming active master else false if anothermaster was running or if some other problem (zookeeper, stop flag has been set on this Master)
 */
boolean blockUntilBecomingActiveMaster(int checkInterval,MonitoredTask startupStatus){
  String backupZNode=ZNodePaths.joinZNode(this.watcher.znodePaths.backupMasterAddressesZNode,this.sn.toString());
  while (!(master.isAborted() || master.isStopped())) {
    startupStatus.setStatus("String_Node_Str");
    try {
      if (MasterAddressTracker.setMasterAddress(this.watcher,this.watcher.znodePaths.masterAddressZNode,this.sn,infoPort)) {
        if (ZKUtil.checkExists(this.watcher,backupZNode) != -1) {
          LOG.info("String_Node_Str" + backupZNode + "String_Node_Str");
          ZKUtil.deleteNodeFailSilent(this.watcher,backupZNode);
        }
        ZNodeClearer.writeMyEphemeralNodeOnDisk(this.sn.toString());
        startupStatus.setStatus("String_Node_Str");
        this.clusterHasActiveMaster.set(true);
        LOG.info("String_Node_Str" + this.sn);
        return true;
      }
      this.clusterHasActiveMaster.set(true);
      String msg;
      byte[] bytes=ZKUtil.getDataAndWatch(this.watcher,this.watcher.znodePaths.masterAddressZNode);
      if (bytes == null) {
        msg=("String_Node_Str" + "String_Node_Str");
      }
 else {
        ServerName currentMaster;
        try {
          currentMaster=ProtobufUtil.parseServerNameFrom(bytes);
        }
 catch (        DeserializationException e) {
          LOG.warn("String_Node_Str",e);
          continue;
        }
        if (ServerName.isSameAddress(currentMaster,this.sn)) {
          msg=("String_Node_Str" + currentMaster + "String_Node_Str");
          ZKUtil.deleteNode(this.watcher,this.watcher.znodePaths.masterAddressZNode);
          ZNodeClearer.deleteMyEphemeralNodeOnDisk();
        }
 else {
          msg="String_Node_Str" + currentMaster + "String_Node_Str";
        }
      }
      LOG.info(msg);
      startupStatus.setStatus(msg);
    }
 catch (    KeeperException ke) {
      master.abort("String_Node_Str",ke);
      return false;
    }
synchronized (this.clusterHasActiveMaster) {
      while (clusterHasActiveMaster.get() && !master.isStopped()) {
        try {
          clusterHasActiveMaster.wait(checkInterval);
        }
 catch (        InterruptedException e) {
          LOG.debug("String_Node_Str",e);
        }
      }
      if (clusterShutDown.get()) {
        this.master.stop("String_Node_Str");
      }
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Block until becoming the active master. Method blocks until there is not another active master and our attempt to become the new active master is successful. This also makes sure that we are watching the master znode so will be notified if another master dies.
 * @param checkInterval the interval to check if the master is stopped
 * @param startupStatus the monitor status to track the progress
 * @return True if no issue becoming active master else false if anothermaster was running or if some other problem (zookeeper, stop flag has been set on this Master)
 */
boolean blockUntilBecomingActiveMaster(int checkInterval,MonitoredTask startupStatus){
  String backupZNode=ZNodePaths.joinZNode(this.watcher.getZNodePaths().backupMasterAddressesZNode,this.sn.toString());
  while (!(master.isAborted() || master.isStopped())) {
    startupStatus.setStatus("String_Node_Str");
    try {
      if (MasterAddressTracker.setMasterAddress(this.watcher,this.watcher.getZNodePaths().masterAddressZNode,this.sn,infoPort)) {
        if (ZKUtil.checkExists(this.watcher,backupZNode) != -1) {
          LOG.info("String_Node_Str" + backupZNode + "String_Node_Str");
          ZKUtil.deleteNodeFailSilent(this.watcher,backupZNode);
        }
        ZNodeClearer.writeMyEphemeralNodeOnDisk(this.sn.toString());
        startupStatus.setStatus("String_Node_Str");
        this.clusterHasActiveMaster.set(true);
        LOG.info("String_Node_Str" + this.sn);
        return true;
      }
      this.clusterHasActiveMaster.set(true);
      String msg;
      byte[] bytes=ZKUtil.getDataAndWatch(this.watcher,this.watcher.getZNodePaths().masterAddressZNode);
      if (bytes == null) {
        msg=("String_Node_Str" + "String_Node_Str");
      }
 else {
        ServerName currentMaster;
        try {
          currentMaster=ProtobufUtil.parseServerNameFrom(bytes);
        }
 catch (        DeserializationException e) {
          LOG.warn("String_Node_Str",e);
          continue;
        }
        if (ServerName.isSameAddress(currentMaster,this.sn)) {
          msg=("String_Node_Str" + currentMaster + "String_Node_Str");
          ZKUtil.deleteNode(this.watcher,this.watcher.getZNodePaths().masterAddressZNode);
          ZNodeClearer.deleteMyEphemeralNodeOnDisk();
        }
 else {
          msg="String_Node_Str" + currentMaster + "String_Node_Str";
        }
      }
      LOG.info(msg);
      startupStatus.setStatus(msg);
    }
 catch (    KeeperException ke) {
      master.abort("String_Node_Str",ke);
      return false;
    }
synchronized (this.clusterHasActiveMaster) {
      while (clusterHasActiveMaster.get() && !master.isStopped()) {
        try {
          clusterHasActiveMaster.wait(checkInterval);
        }
 catch (        InterruptedException e) {
          LOG.debug("String_Node_Str",e);
        }
      }
      if (clusterShutDown.get()) {
        this.master.stop("String_Node_Str");
      }
    }
  }
  return false;
}