Program: 113499
Project: 113499
Buggy source:
@Override public void startRequest(MRCRequest rq) throws Throwable {
  if (master.getReplMasterUUID() != null && !master.getReplMasterUUID().equals(master.getConfig().getUUID().toString()))   throw new DatabaseException(ExceptionType.REDIRECT);
  final xtreemfs_replica_removeRequest rqArgs=(xtreemfs_replica_removeRequest)rq.getRequestArgs();
  final FileAccessManager faMan=master.getFileAccessManager();
  final VolumeManager vMan=master.getVolumeManager();
  validateContext(rq);
  StorageManager sMan;
  FileMetadata file;
  String volumeId;
  if (rqArgs.hasFileId()) {
    GlobalFileIdResolver idRes=new GlobalFileIdResolver(rqArgs.getFileId());
    volumeId=idRes.getVolumeId();
    sMan=vMan.getStorageManager(idRes.getVolumeId());
    file=sMan.getMetadata(idRes.getLocalFileId());
    if (file == null)     throw new UserException(POSIXErrno.POSIX_ERROR_ENOENT,"String_Node_Str" + rqArgs.getFileId() + "String_Node_Str");
  }
 else   if (rqArgs.hasVolumeName() && rqArgs.hasPath()) {
    final Path p=new Path(rqArgs.getVolumeName(),rqArgs.getPath());
    sMan=vMan.getStorageManagerByName(p.getComp(0));
    volumeId=sMan.getVolumeInfo().getId();
    final PathResolver res=new PathResolver(sMan,p);
    res.checkIfFileDoesNotExist();
    file=res.getFile();
    faMan.checkSearchPermission(sMan,res,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  }
 else   throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
  if (file.isDirectory())   throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
  if (sMan.getSoftlinkTarget(file.getId()) != null)   throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + rqArgs.getFileId() + "String_Node_Str");
  faMan.checkPrivilegedPermissions(sMan,file,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  XLocList oldXLocList=file.getXLocList();
  assert(oldXLocList != null);
  int i=0;
  for (; i < oldXLocList.getReplicaCount(); i++) {
    XLoc replica=oldXLocList.getReplica(i);
    if (replica.getOSD(0).equals(rqArgs.getOsdUuid()))     break;
  }
  XLoc[] newReplList=new XLoc[oldXLocList.getReplicaCount() - 1];
  for (int j=0, count=0; j < oldXLocList.getReplicaCount(); j++)   if (j != i)   newReplList[count++]=oldXLocList.getReplica(j);
  XLocList newXLocList=sMan.createXLocList(newReplList,oldXLocList.getReplUpdatePolicy(),oldXLocList.getVersion() + 1);
  file.setXLocList(newXLocList);
  if (newXLocList.getReplicaCount() == 1)   file.setReadOnly(false);
  AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
  sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
  Capability deleteCap=new Capability(volumeId + "String_Node_Str" + file.getId(),FileAccessManager.NON_POSIX_DELETE,master.getConfig().getCapabilityTimeout(),Integer.MAX_VALUE,((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress().getHostAddress(),file.getEpoch(),false,!sMan.getVolumeInfo().isSnapshotsEnabled() ? SnapConfig.SNAP_CONFIG_SNAPS_DISABLED : sMan.getVolumeInfo().isSnapVolume() ? SnapConfig.SNAP_CONFIG_ACCESS_SNAP : SnapConfig.SNAP_CONFIG_ACCESS_CURRENT,sMan.getVolumeInfo().getCreationTime(),master.getConfig().getCapabilitySecret());
  XLocSet.Builder xLocSet=Converter.xLocListToXLocSet(oldXLocList);
  FileCredentials fc=FileCredentials.newBuilder().setXcap(deleteCap.getXCap()).setXlocs(xLocSet).build();
  rq.setResponse(fc);
  update.execute();
}

Fixed version (ground truth):
@Override public void startRequest(MRCRequest rq) throws Throwable {
  if (master.getReplMasterUUID() != null && !master.getReplMasterUUID().equals(master.getConfig().getUUID().toString()))   throw new DatabaseException(ExceptionType.REDIRECT);
  final xtreemfs_replica_removeRequest rqArgs=(xtreemfs_replica_removeRequest)rq.getRequestArgs();
  final FileAccessManager faMan=master.getFileAccessManager();
  final VolumeManager vMan=master.getVolumeManager();
  validateContext(rq);
  StorageManager sMan;
  FileMetadata file;
  String volumeId;
  if (rqArgs.hasFileId()) {
    GlobalFileIdResolver idRes=new GlobalFileIdResolver(rqArgs.getFileId());
    volumeId=idRes.getVolumeId();
    sMan=vMan.getStorageManager(idRes.getVolumeId());
    file=sMan.getMetadata(idRes.getLocalFileId());
    if (file == null)     throw new UserException(POSIXErrno.POSIX_ERROR_ENOENT,"String_Node_Str" + rqArgs.getFileId() + "String_Node_Str");
  }
 else   if (rqArgs.hasVolumeName() && rqArgs.hasPath()) {
    final Path p=new Path(rqArgs.getVolumeName(),rqArgs.getPath());
    sMan=vMan.getStorageManagerByName(p.getComp(0));
    volumeId=sMan.getVolumeInfo().getId();
    final PathResolver res=new PathResolver(sMan,p);
    res.checkIfFileDoesNotExist();
    file=res.getFile();
    faMan.checkSearchPermission(sMan,res,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  }
 else   throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
  if (file.isDirectory())   throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
  if (sMan.getSoftlinkTarget(file.getId()) != null)   throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + rqArgs.getFileId() + "String_Node_Str");
  faMan.checkPrivilegedPermissions(sMan,file,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  XLocList oldXLocList=file.getXLocList();
  assert(oldXLocList != null);
  int i=0;
  for (; i < oldXLocList.getReplicaCount(); i++) {
    XLoc replica=oldXLocList.getReplica(i);
    if (replica.getOSD(0).equals(rqArgs.getOsdUuid()))     break;
  }
  if (i == oldXLocList.getReplicaCount())   throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + rqArgs.getOsdUuid() + "String_Node_Str");
  XLoc[] newReplList=new XLoc[oldXLocList.getReplicaCount() - 1];
  for (int j=0, count=0; j < oldXLocList.getReplicaCount(); j++)   if (j != i)   newReplList[count++]=oldXLocList.getReplica(j);
  XLocList newXLocList=sMan.createXLocList(newReplList,oldXLocList.getReplUpdatePolicy(),oldXLocList.getVersion() + 1);
  file.setXLocList(newXLocList);
  if (newXLocList.getReplicaCount() == 1)   file.setReadOnly(false);
  AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
  sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
  Capability deleteCap=new Capability(volumeId + "String_Node_Str" + file.getId(),FileAccessManager.NON_POSIX_DELETE,master.getConfig().getCapabilityTimeout(),Integer.MAX_VALUE,((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress().getHostAddress(),file.getEpoch(),false,!sMan.getVolumeInfo().isSnapshotsEnabled() ? SnapConfig.SNAP_CONFIG_SNAPS_DISABLED : sMan.getVolumeInfo().isSnapVolume() ? SnapConfig.SNAP_CONFIG_ACCESS_SNAP : SnapConfig.SNAP_CONFIG_ACCESS_CURRENT,sMan.getVolumeInfo().getCreationTime(),master.getConfig().getCapabilitySecret());
  XLocSet.Builder xLocSet=Converter.xLocListToXLocSet(oldXLocList);
  FileCredentials fc=FileCredentials.newBuilder().setXcap(deleteCap.getXCap()).setXlocs(xLocSet).build();
  rq.setResponse(fc);
  update.execute();
}