Program: 154584
Project: 154584
Buggy source:
public void process(WatchedEvent event){
  try {
    String path=event.getPath();
    msgLog.logMessage(this + "String_Node_Str" + new Date()+ "String_Node_Str"+ event+ "String_Node_Str"+ path+ "String_Node_Str",true);
    if (path == null && event.getState() == Watcher.Event.KeeperState.Expired) {
      keeperState=KeeperState.Expired;
      if (zooKeeper != null) {
        try {
          zooKeeper.close();
        }
 catch (        InterruptedException e) {
          e.printStackTrace();
          Thread.interrupted();
        }
      }
      zooKeeper=instantiateZooKeeper();
    }
 else     if (path == null && event.getState() == Watcher.Event.KeeperState.SyncConnected) {
      long newSessionId=zooKeeper.getSessionId();
      Pair<Master,Machine> masterBeforeIWrite=getMasterFromZooKeeper(false);
      msgLog.logMessage("String_Node_Str" + masterBeforeIWrite);
      boolean masterBeforeIWriteDiffers=masterBeforeIWrite.other().getMachineId() != getCachedMaster().other().getMachineId();
      if (newSessionId != sessionId || masterBeforeIWriteDiffers) {
        sequenceNr=setup();
        msgLog.logMessage("String_Node_Str" + sequenceNr + "String_Node_Str"+ newSessionId);
        keeperState=KeeperState.SyncConnected;
        Pair<Master,Machine> masterAfterIWrote=getMasterFromZooKeeper(false);
        msgLog.logMessage("String_Node_Str" + masterAfterIWrote);
        int masterId=masterAfterIWrote.other().getMachineId();
        setDataChangeWatcher(MASTER_NOTIFY_CHILD,masterId);
        if (sessionId != -1) {
          receiver.newMaster(masterAfterIWrote,new Exception());
        }
        sessionId=newSessionId;
      }
 else {
        msgLog.logMessage("String_Node_Str" + sessionId);
        keeperState=KeeperState.SyncConnected;
      }
    }
 else     if (path == null && event.getState() == Watcher.Event.KeeperState.Disconnected) {
      keeperState=KeeperState.Disconnected;
    }
 else     if (event.getType() == Watcher.Event.EventType.NodeDataChanged) {
      Pair<Master,Machine> currentMaster=getMasterFromZooKeeper(true);
      if (path.contains(MASTER_NOTIFY_CHILD)) {
        setDataChangeWatcher(MASTER_NOTIFY_CHILD,-1);
        if (currentMaster.other().getMachineId() == machineId) {
          receiver.newMaster(currentMaster,new Exception());
        }
      }
 else       if (path.contains(MASTER_REBOUND_CHILD)) {
        setDataChangeWatcher(MASTER_REBOUND_CHILD,-1);
        if (currentMaster.other().getMachineId() != machineId) {
          receiver.newMaster(currentMaster,new Exception());
        }
      }
 else {
        msgLog.logMessage("String_Node_Str" + path);
      }
    }
  }
 catch (  RuntimeException e) {
    msgLog.logMessage("String_Node_Str",e,true);
    e.printStackTrace();
    throw e;
  }
 finally {
    msgLog.flush();
  }
}

Fixed version (ground truth):
public void process(WatchedEvent event){
  try {
    String path=event.getPath();
    msgLog.logMessage(this + "String_Node_Str" + new Date()+ "String_Node_Str"+ event+ "String_Node_Str"+ path+ "String_Node_Str",true);
    if (path == null && event.getState() == Watcher.Event.KeeperState.Expired) {
      keeperState=KeeperState.Expired;
      if (zooKeeper != null) {
        try {
          zooKeeper.close();
        }
 catch (        InterruptedException e) {
          e.printStackTrace();
          Thread.interrupted();
        }
      }
      zooKeeper=instantiateZooKeeper();
    }
 else     if (path == null && event.getState() == Watcher.Event.KeeperState.SyncConnected) {
      long newSessionId=zooKeeper.getSessionId();
      Pair<Master,Machine> masterBeforeIWrite=getMasterFromZooKeeper(false);
      msgLog.logMessage("String_Node_Str" + masterBeforeIWrite);
      boolean masterBeforeIWriteDiffers=masterBeforeIWrite.other().getMachineId() != getCachedMaster().other().getMachineId();
      if (newSessionId != sessionId || masterBeforeIWriteDiffers) {
        sequenceNr=setup();
        msgLog.logMessage("String_Node_Str" + sequenceNr + "String_Node_Str"+ newSessionId);
        keeperState=KeeperState.SyncConnected;
        Pair<Master,Machine> masterAfterIWrote=getMasterFromZooKeeper(false);
        msgLog.logMessage("String_Node_Str" + masterAfterIWrote);
        int masterId=masterAfterIWrote.other().getMachineId();
        msgLog.logMessage("String_Node_Str" + MASTER_NOTIFY_CHILD + "String_Node_Str"+ masterId);
        setDataChangeWatcher(MASTER_NOTIFY_CHILD,masterId);
        msgLog.logMessage("String_Node_Str" + MASTER_NOTIFY_CHILD + "String_Node_Str"+ masterId);
        if (sessionId != -1) {
          receiver.newMaster(masterAfterIWrote,new Exception());
        }
        sessionId=newSessionId;
      }
 else {
        msgLog.logMessage("String_Node_Str" + sessionId);
        keeperState=KeeperState.SyncConnected;
      }
    }
 else     if (path == null && event.getState() == Watcher.Event.KeeperState.Disconnected) {
      keeperState=KeeperState.Disconnected;
    }
 else     if (event.getType() == Watcher.Event.EventType.NodeDataChanged) {
      Pair<Master,Machine> currentMaster=getMasterFromZooKeeper(true);
      if (path.contains(MASTER_NOTIFY_CHILD)) {
        setDataChangeWatcher(MASTER_NOTIFY_CHILD,-1);
        if (currentMaster.other().getMachineId() == machineId) {
          receiver.newMaster(currentMaster,new Exception());
        }
      }
 else       if (path.contains(MASTER_REBOUND_CHILD)) {
        setDataChangeWatcher(MASTER_REBOUND_CHILD,-1);
        if (currentMaster.other().getMachineId() != machineId) {
          receiver.newMaster(currentMaster,new Exception());
        }
      }
 else {
        msgLog.logMessage("String_Node_Str" + path);
      }
    }
  }
 catch (  RuntimeException e) {
    msgLog.logMessage("String_Node_Str",e,true);
    e.printStackTrace();
    throw e;
  }
 finally {
    msgLog.flush();
  }
}