Program: 113512
Project: 113512
Buggy source:
private void processPrepareOp(StageRequest method){
  final RWReplicationCallback callback=(RWReplicationCallback)method.getCallback();
  try {
    final FileCredentials credentials=(FileCredentials)method.getArgs()[0];
    final XLocations loc=(XLocations)method.getArgs()[1];
    final Long objVersion=(Long)method.getArgs()[3];
    final Operation op=(Operation)method.getArgs()[4];
    final String fileId=credentials.getXcap().getFile_id();
    ReplicatedFileState state=getState(credentials,loc,false);
    if ((op == Operation.INTERNAL_UPDATE) || (op == Operation.INTERNAL_TRUNCATE)) {
switch (state.getState()) {
case WAITING_FOR_LEASE:
case INITIALIZING:
case RESET:
{
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",fileId,state.getState());
          }
          if (state.getPendingRequests().size() > MAX_PENDING_PER_FILE) {
            callback.failed(new OSDException(ErrorCodes.IO_ERROR,"String_Node_Str","String_Node_Str"));
          }
 else {
            state.getPendingRequests().add(method);
          }
          return;
        }
    }
    boolean needsReset=state.getPolicy().onRemoteUpdate(objVersion,state.getState());
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",fileId,needsReset);
    }
    if (needsReset) {
      state.getPendingRequests().add(method);
      doReset(state,objVersion);
    }
 else {
      callback.success(0);
    }
  }
 else {
    state.setCredentials(credentials);
switch (state.getState()) {
case WAITING_FOR_LEASE:
case INITIALIZING:
case RESET:
{
        state.getPendingRequests().add(method);
        return;
      }
case OPEN:
{
      state.getPendingRequests().add(method);
      doWaitingForLease(state);
      return;
    }
}
long newVersion=state.getPolicy().onClientOperation(op,objVersion,state.getState(),state.getLease());
callback.success(newVersion);
}
}
 catch (RedirectException ex) {
callback.redirect(ex);
}
catch (Exception ex) {
ex.printStackTrace();
callback.failed(ex);
}
}

Fixed version (ground truth):
private void processPrepareOp(StageRequest method){
  final RWReplicationCallback callback=(RWReplicationCallback)method.getCallback();
  try {
    final FileCredentials credentials=(FileCredentials)method.getArgs()[0];
    final XLocations loc=(XLocations)method.getArgs()[1];
    final Long objVersion=(Long)method.getArgs()[3];
    final Operation op=(Operation)method.getArgs()[4];
    final String fileId=credentials.getXcap().getFile_id();
    ReplicatedFileState state=getState(credentials,loc,false);
    if ((op == Operation.INTERNAL_UPDATE) || (op == Operation.INTERNAL_TRUNCATE)) {
switch (state.getState()) {
case WAITING_FOR_LEASE:
case INITIALIZING:
case RESET:
case OPEN:
{
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",fileId,state.getState());
          }
          if (state.getPendingRequests().size() > MAX_PENDING_PER_FILE) {
            callback.failed(new OSDException(ErrorCodes.IO_ERROR,"String_Node_Str","String_Node_Str"));
          }
 else {
            state.getPendingRequests().add(method);
          }
          if (state.getState() == ReplicaState.OPEN) {
            doBackup(state);
          }
          return;
        }
    }
    boolean needsReset=state.getPolicy().onRemoteUpdate(objVersion,state.getState());
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",fileId,needsReset);
    }
    if (needsReset) {
      state.getPendingRequests().add(method);
      doReset(state,objVersion);
    }
 else {
      callback.success(0);
    }
  }
 else {
    state.setCredentials(credentials);
switch (state.getState()) {
case WAITING_FOR_LEASE:
case INITIALIZING:
case RESET:
{
        state.getPendingRequests().add(method);
        return;
      }
case OPEN:
{
      state.getPendingRequests().add(method);
      doWaitingForLease(state);
      return;
    }
}
long newVersion=state.getPolicy().onClientOperation(op,objVersion,state.getState(),state.getLease());
callback.success(newVersion);
}
}
 catch (RedirectException ex) {
callback.redirect(ex);
}
catch (Exception ex) {
ex.printStackTrace();
callback.failed(ex);
}
}