Program: 132398
Project: 132398
Buggy source:
/** 
 * <p> Makes the locally BabuDB running in master-mode. </p> <p> Stops all declared slaves and synchronizes the local BabuDB  with the latest slave. Then restarts all participants in slave mode  </p>
 * @param conf
 * @throws NotEnoughAvailableSlavesException 
 * @throws IOException 
 * @throws InterruptedException 
 * @throws ONCRPCException 
 */
public void declareToMaster(MasterConfig conf) throws NotEnoughAvailableSlavesException, IOException, ONCRPCException, InterruptedException {
  if (dispatcher.isMaster)   return;
  Map<InetSocketAddress,LSN> states=stopAll(conf.getSlaves());
  if (states.size() < conf.getSyncN())   throw new NotEnoughAvailableSlavesException("String_Node_Str");
  List<LSN> values=new LinkedList<LSN>(states.values());
  Collections.sort(values);
  LSN latest=values.get(values.size() - 1);
  String backupDir=new File(conf.getBaseDir()).getParent() + File.separator + "String_Node_Str";
  DispatcherState state=stop();
  if (state.requestQueue != null)   for (  StageRequest rq : state.requestQueue)   rq.free();
  if (latest.compareTo(state.latest) > 0) {
    for (    Entry<InetSocketAddress,LSN> entry : states.entrySet()) {
      if (entry.getValue().equals(latest)) {
        set(new SlaveConfig(conf,entry.getKey(),backupDir),dispatcher.new DispatcherState(state.latest));
        StateClient c=new StateClient(dispatcher.rpcClient,entry.getKey());
        c.toMaster(conf.getMaster()).get();
        ((SlaveRequestDispatcher)dispatcher).synchronize(latest);
        c.remoteStop().get();
        break;
      }
    }
    state=stop();
  }
  allToSlaves(conf.getSlaves(),conf.getSyncN(),conf.getMaster());
  set(conf,state);
}

Fixed version (ground truth):
/** 
 * <p> Makes the locally BabuDB running in master-mode. </p> <p> Stops all declared slaves and synchronizes the local BabuDB  with the latest slave. Then restarts all participants in slave mode  </p>
 * @param conf
 * @throws NotEnoughAvailableSlavesException 
 * @throws IOException 
 * @throws InterruptedException 
 * @throws ONCRPCException 
 * @throws BabuDBException 
 */
public void declareToMaster(MasterConfig conf) throws NotEnoughAvailableSlavesException, IOException, ONCRPCException, InterruptedException, BabuDBException {
  if (dispatcher.isMaster)   return;
  Map<InetSocketAddress,LSN> states=stopAll(conf.getSlaves());
  if (states.size() < conf.getSyncN())   throw new NotEnoughAvailableSlavesException("String_Node_Str");
  List<LSN> values=new LinkedList<LSN>(states.values());
  Collections.sort(values);
  LSN latest=values.get(values.size() - 1);
  String backupDir=new File(conf.getBaseDir()).getParent() + File.separator + "String_Node_Str";
  DispatcherState state=stop();
  if (state.requestQueue != null)   for (  StageRequest rq : state.requestQueue)   rq.free();
  if (latest.compareTo(state.latest) > 0) {
    for (    Entry<InetSocketAddress,LSN> entry : states.entrySet()) {
      if (entry.getValue().equals(latest)) {
        changeConfiguration(new SlaveConfig(conf,entry.getKey(),backupDir));
        StateClient c=new StateClient(dispatcher.rpcClient,entry.getKey());
        c.toMaster(conf.getMaster()).get();
        ((SlaveRequestDispatcher)dispatcher).synchronize(latest);
        c.remoteStop().get();
        break;
      }
    }
  }
  allToSlaves(conf.getSlaves(),conf.getSyncN(),conf.getMaster());
  changeConfiguration(conf);
}