Program: 113333
Project: 113333
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().getFileId();
    ReplicatedFileState state=getState(credentials,loc,false,false);
    if (state.isInvalidated()) {
      callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
      return;
    }
    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.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
            if (Logging.isDebug()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
            }
            callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
            return;
          }
 else {
            state.addPendingRequest(method);
          }
          return;
        }
case OPEN:
{
        if (Logging.isDebug()) {
          Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",fileId,state.getState());
        }
        if (state.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
          }
          callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
          return;
        }
 else {
          state.addPendingRequest(method);
        }
        doWaitingForLease(state);
        return;
      }
  }
  if (!state.getPolicy().acceptRemoteUpdate(objVersion)) {
    Logging.logMessage(Logging.LEVEL_WARN,Category.replication,this,"String_Node_Str",objVersion,fileId);
    callback.failed(ErrorUtils.getErrorResponse(ErrorType.IO_ERROR,POSIXErrno.POSIX_ERROR_EIO,"String_Node_Str"));
    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.addPendingRequest(method);
    doReset(state,objVersion);
  }
 else {
    callback.success(0);
  }
}
 else {
  state.setCredentials(credentials);
switch (state.getState()) {
case WAITING_FOR_LEASE:
case INITIALIZING:
case RESET:
{
      if (state.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
        if (Logging.isDebug()) {
          Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
        }
        callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
      }
 else {
        state.addPendingRequest(method);
      }
      return;
    }
case OPEN:
{
    if (state.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
      if (Logging.isDebug()) {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
      }
      callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
      return;
    }
 else {
      state.addPendingRequest(method);
    }
    doWaitingForLease(state);
    return;
  }
}
try {
long newVersion=state.getPolicy().onClientOperation(op,objVersion,state.getState(),state.getLease());
callback.success(newVersion);
}
 catch (RedirectToMasterException ex) {
callback.redirect(ex.getMasterUUID());
}
catch (RetryException ex) {
final ErrorResponse err=ErrorUtils.getInternalServerError(ex);
failed(state,err,"String_Node_Str");
if (state.getState() == ReplicaState.BACKUP || state.getState() == ReplicaState.PRIMARY) {
  callback.failed(err);
}
}
}
}
 catch (Exception ex) {
ex.printStackTrace();
callback.failed(ErrorUtils.getInternalServerError(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().getFileId();
    ReplicatedFileState state=getState(credentials,loc,false,false);
    if (state.isInvalidated()) {
      callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
      return;
    }
    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.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
            if (Logging.isDebug()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
            }
            callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
            return;
          }
 else {
            state.addPendingRequest(method);
          }
          if (state.getState() == ReplicaState.OPEN) {
            doWaitingForLease(state);
          }
          return;
        }
    }
    if (!state.getPolicy().acceptRemoteUpdate(objVersion)) {
      Logging.logMessage(Logging.LEVEL_WARN,Category.replication,this,"String_Node_Str",objVersion,fileId);
      callback.failed(ErrorUtils.getErrorResponse(ErrorType.IO_ERROR,POSIXErrno.POSIX_ERROR_EIO,"String_Node_Str"));
      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.addPendingRequest(method);
      doReset(state,objVersion);
    }
 else {
      callback.success(0);
    }
  }
 else {
    state.setCredentials(credentials);
switch (state.getState()) {
case WAITING_FOR_LEASE:
case INITIALIZING:
case RESET:
{
        if (state.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
          }
          callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
        }
 else {
          state.addPendingRequest(method);
        }
        return;
      }
case OPEN:
{
      if (state.sizeOfPendingRequests() > MAX_PENDING_PER_FILE) {
        if (Logging.isDebug()) {
          Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",state.sizeOfPendingRequests(),MAX_PENDING_PER_FILE,fileId);
        }
        callback.failed(ErrorUtils.getErrorResponse(ErrorType.INTERNAL_SERVER_ERROR,POSIXErrno.POSIX_ERROR_NONE,"String_Node_Str"));
        return;
      }
 else {
        state.addPendingRequest(method);
      }
      doWaitingForLease(state);
      return;
    }
}
try {
  long newVersion=state.getPolicy().onClientOperation(op,objVersion,state.getState(),state.getLease());
  callback.success(newVersion);
}
 catch (RedirectToMasterException ex) {
  callback.redirect(ex.getMasterUUID());
}
catch (RetryException ex) {
  final ErrorResponse err=ErrorUtils.getInternalServerError(ex);
  failed(state,err,"String_Node_Str");
  if (state.getState() == ReplicaState.BACKUP || state.getState() == ReplicaState.PRIMARY) {
    callback.failed(err);
  }
}
}
}
 catch (Exception ex) {
ex.printStackTrace();
callback.failed(ErrorUtils.getInternalServerError(ex));
}
}