Program: 132382
Project: 132382
Buggy source:
public void declareToMaster() throws NotEnoughAvailableSlavesException, IOException, ONCRPCException, InterruptedException, BabuDBException {
  if (dispatcher.isMaster)   return;
  DispatcherState state=stop();
  if (state.requestQueue != null)   for (  StageRequest rq : state.requestQueue)   rq.free();
  state.requestQueue=null;
  this.dispatcher=new SlaveRequestDispatcher(this.dispatcher);
  SlaveRequestDispatcher lDisp=(SlaveRequestDispatcher)dispatcher;
  List<InetSocketAddress> slaves=new LinkedList<InetSocketAddress>(dispatcher.configuration.getParticipants());
  slaves.remove(dispatcher.configuration.getInetSocketAddress());
  if (slaves.size() > 0) {
    Map<InetSocketAddress,LSN> states=stopAll(slaves);
    if (states.size() < dispatcher.configuration.getSyncN())     throw new NotEnoughAvailableSlavesException("String_Node_Str");
    if (states.size() > 0) {
      List<LSN> values=new LinkedList<LSN>(states.values());
      Collections.sort(values);
      LSN latest=values.get(values.size() - 1);
      if (latest.compareTo(state.latest) > 0) {
        for (        Entry<InetSocketAddress,LSN> entry : states.entrySet()) {
          if (entry.getValue().equals(latest)) {
            lDisp.coin(entry.getKey());
            StateClient c=new StateClient(dispatcher.rpcClient,entry.getKey());
            RPCResponse<Object> rp=null;
            try {
              rp=c.toMaster();
              rp.get();
            }
  finally {
              if (rp != null)               rp.freeBuffers();
            }
            lDisp.synchronize(state.latest,latest);
            RPCResponse<LSN> rps=null;
            try {
              rps=c.remoteStop();
              rps.get();
            }
  finally {
              if (rps != null)               rps.freeBuffers();
            }
            break;
          }
        }
      }
    }
    allToSlaves(slaves,dispatcher.configuration.getSyncN(),dispatcher.configuration.getInetSocketAddress());
  }
  this.dispatcher=new MasterRequestDispatcher(dispatcher,dispatcher.configuration.getInetSocketAddress());
  restart(state);
}

Fixed version (ground truth):
public void declareToMaster() throws NotEnoughAvailableSlavesException, IOException, ONCRPCException, InterruptedException, BabuDBException {
  if (dispatcher.isMaster)   return;
  DispatcherState state=null;
  if (isRunning()) {
    state=stop();
  }
 else {
    state=dispatcher.getState();
  }
  if (state.requestQueue != null)   for (  StageRequest rq : state.requestQueue)   rq.free();
  state.requestQueue=null;
  this.dispatcher=new SlaveRequestDispatcher(this.dispatcher);
  SlaveRequestDispatcher lDisp=(SlaveRequestDispatcher)dispatcher;
  List<InetSocketAddress> slaves=new LinkedList<InetSocketAddress>(dispatcher.configuration.getParticipants());
  slaves.remove(dispatcher.configuration.getInetSocketAddress());
  if (slaves.size() > 0) {
    Map<InetSocketAddress,LSN> states=stopAll(slaves);
    if (states.size() < dispatcher.configuration.getSyncN())     throw new NotEnoughAvailableSlavesException("String_Node_Str");
    if (states.size() > 0) {
      List<LSN> values=new LinkedList<LSN>(states.values());
      Collections.sort(values);
      LSN latest=values.get(values.size() - 1);
      if (latest.compareTo(state.latest) > 0) {
        for (        Entry<InetSocketAddress,LSN> entry : states.entrySet()) {
          if (entry.getValue().equals(latest)) {
            lDisp.coin(entry.getKey());
            StateClient c=new StateClient(dispatcher.rpcClient,entry.getKey());
            RPCResponse<Object> rp=null;
            try {
              rp=c.toMaster();
              rp.get();
            }
  finally {
              if (rp != null)               rp.freeBuffers();
            }
            lDisp.synchronize(state.latest,latest);
            RPCResponse<LSN> rps=null;
            try {
              rps=c.remoteStop();
              rps.get();
            }
  finally {
              if (rps != null)               rps.freeBuffers();
            }
            break;
          }
        }
      }
    }
    allToSlaves(slaves,dispatcher.configuration.getSyncN(),dispatcher.configuration.getInetSocketAddress());
  }
  this.dispatcher=new MasterRequestDispatcher(dispatcher,dispatcher.configuration.getInetSocketAddress());
  restart(state);
}