Program: 113342
Project: 113342
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 renameRequest rqArgs=(renameRequest)rq.getRequestArgs();
  final VolumeManager vMan=master.getVolumeManager();
  final FileAccessManager faMan=master.getFileAccessManager();
  validateContext(rq);
  final Path sp=new Path(rqArgs.getVolumeName(),rqArgs.getSourcePath());
  final StorageManager sMan=vMan.getStorageManagerByName(sp.getComp(0));
  final PathResolver sRes=new PathResolver(sMan,sp);
  final VolumeInfo volume=sMan.getVolumeInfo();
  faMan.checkSearchPermission(sMan,sRes,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  faMan.checkPermission(FileAccessManager.O_WRONLY,sMan,sRes.getParentDir(),sRes.getParentsParentId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  Path tp=new Path(rqArgs.getVolumeName(),rqArgs.getTargetPath());
  if (sp.getCompCount() == 1)   throw new UserException(POSIXErrno.POSIX_ERROR_ENOENT,"String_Node_Str");
  if (!sp.getComp(0).equals(tp.getComp(0)))   throw new UserException(POSIXErrno.POSIX_ERROR_ENOENT,"String_Node_Str");
  sRes.checkIfFileDoesNotExist();
  faMan.checkPermission(FileAccessManager.NON_POSIX_RM_MV_IN_DIR,sMan,sRes.getFile(),sRes.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  FileMetadata source=sRes.getFile();
  FileType sourceType=source.isDirectory() ? FileType.dir : FileType.file;
  AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
  PathResolver tRes=null;
  tRes=new PathResolver(sMan,tp);
  FileMetadata targetParentDir=tRes.getParentDir();
  if (targetParentDir == null || !targetParentDir.isDirectory())   throw new UserException(POSIXErrno.POSIX_ERROR_ENOTDIR,"String_Node_Str" + tp.getComps(0,tp.getCompCount() - 2) + "String_Node_Str");
  FileMetadata target=tRes.getFile();
  FileType targetType=tp.getCompCount() == 1 ? FileType.dir : target == null ? FileType.nexists : target.isDirectory() ? FileType.dir : FileType.file;
  FileCredentials.Builder creds=null;
  if (sp.equals(tp)) {
    rq.setResponse(buildResponse(0,creds));
    finishRequest(rq);
    return;
  }
  faMan.checkSearchPermission(sMan,tRes,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  faMan.checkPermission(FileAccessManager.O_WRONLY,sMan,tRes.getParentDir(),tRes.getParentsParentId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  int time=(int)(TimeSync.getGlobalTime() / 1000);
switch (sourceType) {
case dir:
{
      if (tp.isSubDirOf(sp))       throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + sp + "String_Node_Str");
switch (targetType) {
case nexists:
{
          relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
          break;
        }
case dir:
{
        faMan.checkPermission(FileAccessManager.NON_POSIX_DELETE,sMan,target,tRes.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
        DatabaseResultSet<FileMetadata> children=sMan.getChildren(target.getId(),0,Integer.MAX_VALUE);
        boolean hasChildren=children.hasNext();
        children.destroy();
        if (hasChildren)         throw new UserException(POSIXErrno.POSIX_ERROR_ENOTEMPTY,"String_Node_Str" + tRes + "String_Node_Str");
 else {
          FileMetadata metadata=sMan.getMetadata(tRes.getParentDirId(),tRes.getFileName());
          QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),metadata);
          master.getMrcVoucherManager().deleteFile(quotaFileInformation,update);
          sMan.delete(tRes.getParentDirId(),tRes.getFileName(),update);
        }
        relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
        break;
      }
case file:
    throw new UserException(POSIXErrno.POSIX_ERROR_ENOTDIR,"String_Node_Str" + sRes + "String_Node_Str"+ tRes+ "String_Node_Str");
}
break;
}
case file:
{
switch (targetType) {
case nexists:
{
  relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
  break;
}
case dir:
{
throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str" + sRes + "String_Node_Str"+ tRes+ "String_Node_Str");
}
case file:
{
faMan.checkPermission(FileAccessManager.NON_POSIX_RM_MV_IN_DIR,sMan,tRes.getFile(),tRes.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
if (sMan.getSoftlinkTarget(target.getId()) == null && target.getLinkCount() == 1) {
Capability cap=new Capability(MRCHelper.createGlobalFileId(volume,target),FileAccessManager.NON_POSIX_DELETE,master.getConfig().getCapabilityTimeout(),Integer.MAX_VALUE,((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress().getHostAddress(),target.getEpoch(),false,!volume.isSnapshotsEnabled() ? SnapConfig.SNAP_CONFIG_SNAPS_DISABLED : volume.isSnapVolume() ? SnapConfig.SNAP_CONFIG_ACCESS_SNAP : SnapConfig.SNAP_CONFIG_ACCESS_CURRENT,volume.getCreationTime(),master.getConfig().getCapabilitySecret());
creds=FileCredentials.newBuilder().setXcap(cap.getXCap()).setXlocs(Converter.xLocListToXLocSet(target.getXLocList()));
}
FileMetadata metadata=sMan.getMetadata(tRes.getParentDirId(),tRes.getFileName());
QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),metadata);
master.getMrcVoucherManager().deleteFile(quotaFileInformation,update);
sMan.delete(tRes.getParentDirId(),tRes.getFileName(),update);
relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
break;
}
}
}
}
MRCHelper.updateFileTimes(sRes.getParentsParentId(),sRes.getParentDir(),false,true,true,sMan,time,update);
MRCHelper.updateFileTimes(tRes.getParentsParentId(),tRes.getParentDir(),false,true,true,sMan,time,update);
rq.setResponse(buildResponse(time,creds));
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 renameRequest rqArgs=(renameRequest)rq.getRequestArgs();
  final VolumeManager vMan=master.getVolumeManager();
  final FileAccessManager faMan=master.getFileAccessManager();
  validateContext(rq);
  final Path sp=new Path(rqArgs.getVolumeName(),rqArgs.getSourcePath());
  final StorageManager sMan=vMan.getStorageManagerByName(sp.getComp(0));
  final PathResolver sRes=new PathResolver(sMan,sp);
  final VolumeInfo volume=sMan.getVolumeInfo();
  faMan.checkSearchPermission(sMan,sRes,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  faMan.checkPermission(FileAccessManager.O_WRONLY,sMan,sRes.getParentDir(),sRes.getParentsParentId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  Path tp=new Path(rqArgs.getVolumeName(),rqArgs.getTargetPath());
  if (sp.getCompCount() == 1)   throw new UserException(POSIXErrno.POSIX_ERROR_ENOENT,"String_Node_Str");
  if (!sp.getComp(0).equals(tp.getComp(0)))   throw new UserException(POSIXErrno.POSIX_ERROR_ENOENT,"String_Node_Str");
  sRes.checkIfFileDoesNotExist();
  faMan.checkPermission(FileAccessManager.NON_POSIX_RM_MV_IN_DIR,sMan,sRes.getFile(),sRes.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  FileMetadata source=sRes.getFile();
  FileType sourceType=source.isDirectory() ? FileType.dir : FileType.file;
  AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
  PathResolver tRes=null;
  tRes=new PathResolver(sMan,tp);
  FileMetadata targetParentDir=tRes.getParentDir();
  if (targetParentDir == null || !targetParentDir.isDirectory())   throw new UserException(POSIXErrno.POSIX_ERROR_ENOTDIR,"String_Node_Str" + tp.getComps(0,tp.getCompCount() - 2) + "String_Node_Str");
  FileMetadata target=tRes.getFile();
  FileType targetType=tp.getCompCount() == 1 ? FileType.dir : target == null ? FileType.nexists : target.isDirectory() ? FileType.dir : FileType.file;
  FileCredentials.Builder creds=null;
  if (sp.equals(tp)) {
    rq.setResponse(buildResponse(0,creds));
    finishRequest(rq);
    return;
  }
  faMan.checkSearchPermission(sMan,tRes,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  faMan.checkPermission(FileAccessManager.O_WRONLY,sMan,tRes.getParentDir(),tRes.getParentsParentId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  int time=(int)(TimeSync.getGlobalTime() / 1000);
switch (sourceType) {
case dir:
{
      if (tp.isSubDirOf(sp))       throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + sp + "String_Node_Str");
switch (targetType) {
case nexists:
{
          relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
          break;
        }
case dir:
{
        faMan.checkPermission(FileAccessManager.NON_POSIX_DELETE,sMan,target,tRes.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
        DatabaseResultSet<FileMetadata> children=sMan.getChildren(target.getId(),0,Integer.MAX_VALUE);
        boolean hasChildren=children.hasNext();
        children.destroy();
        if (hasChildren)         throw new UserException(POSIXErrno.POSIX_ERROR_ENOTEMPTY,"String_Node_Str" + tRes + "String_Node_Str");
 else {
          sMan.delete(tRes.getParentDirId(),tRes.getFileName(),update);
        }
        relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
        break;
      }
case file:
    throw new UserException(POSIXErrno.POSIX_ERROR_ENOTDIR,"String_Node_Str" + sRes + "String_Node_Str"+ tRes+ "String_Node_Str");
}
break;
}
case file:
{
switch (targetType) {
case nexists:
{
  relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
  break;
}
case dir:
{
throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str" + sRes + "String_Node_Str"+ tRes+ "String_Node_Str");
}
case file:
{
faMan.checkPermission(FileAccessManager.NON_POSIX_RM_MV_IN_DIR,sMan,tRes.getFile(),tRes.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
if (sMan.getSoftlinkTarget(target.getId()) == null && target.getLinkCount() == 1) {
Capability cap=new Capability(MRCHelper.createGlobalFileId(volume,target),FileAccessManager.NON_POSIX_DELETE,master.getConfig().getCapabilityTimeout(),Integer.MAX_VALUE,((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress().getHostAddress(),target.getEpoch(),false,!volume.isSnapshotsEnabled() ? SnapConfig.SNAP_CONFIG_SNAPS_DISABLED : volume.isSnapVolume() ? SnapConfig.SNAP_CONFIG_ACCESS_SNAP : SnapConfig.SNAP_CONFIG_ACCESS_CURRENT,volume.getCreationTime(),master.getConfig().getCapabilitySecret());
creds=FileCredentials.newBuilder().setXcap(cap.getXCap()).setXlocs(Converter.xLocListToXLocSet(target.getXLocList()));
}
FileMetadata metadata=sMan.getMetadata(tRes.getParentDirId(),tRes.getFileName());
QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),metadata);
master.getMrcVoucherManager().deleteFile(quotaFileInformation,update);
sMan.delete(tRes.getParentDirId(),tRes.getFileName(),update);
relink(sMan,sRes.getParentDirId(),sRes.getFileName(),source,tRes.getParentDirId(),tRes.getFileName(),update);
break;
}
}
}
}
MRCHelper.updateFileTimes(sRes.getParentsParentId(),sRes.getParentDir(),false,true,true,sMan,time,update);
MRCHelper.updateFileTimes(tRes.getParentsParentId(),tRes.getParentDir(),false,true,true,sMan,time,update);
rq.setResponse(buildResponse(time,creds));
update.execute();
}