Program: 113363
Project: 113363
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 openRequest rqArgs=(openRequest)rq.getRequestArgs();
  final VolumeManager vMan=master.getVolumeManager();
  final FileAccessManager faMan=master.getFileAccessManager();
  Path p=new Path(rqArgs.getVolumeName(),rqArgs.getPath());
  StorageManager sMan=vMan.getStorageManagerByName(p.getComp(0));
  PathResolver res=new PathResolver(sMan,p);
  VolumeInfo volume=sMan.getVolumeInfo();
  faMan.checkSearchPermission(sMan,res,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
  FileMetadata file=null;
  boolean create=(rqArgs.getFlags() & FileAccessManager.O_CREAT) != 0;
  boolean excl=(rqArgs.getFlags() & FileAccessManager.O_EXCL) != 0;
  boolean truncate=(rqArgs.getFlags() & FileAccessManager.O_TRUNC) != 0;
  boolean write=(rqArgs.getFlags() & (FileAccessManager.O_WRONLY | FileAccessManager.O_RDWR)) != 0;
  boolean createNew=false;
  int time=(int)(TimeSync.getGlobalTime() / 1000);
  try {
    res.checkIfFileDoesNotExist();
    if (create && excl)     res.checkIfFileExistsAlready();
    file=res.getFile();
    if (create || truncate || write) {
      QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),file);
      master.getMrcVoucherManager().checkVoucherAvailability(quotaFileInformation);
    }
    if (file.isDirectory() || sMan.getSoftlinkTarget(file.getId()) != null)     throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str");
    if (file.isReadOnly() && ((rqArgs.getFlags() & (FileAccessManager.O_RDWR | FileAccessManager.O_WRONLY | FileAccessManager.O_TRUNC| FileAccessManager.O_APPEND)) != 0))     throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
    faMan.checkPermission(rqArgs.getFlags(),sMan,file,res.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  }
 catch (  UserException exc) {
    if (exc.getErrno() == POSIXErrno.POSIX_ERROR_ENOENT && create) {
      faMan.checkPermission(FileAccessManager.O_WRONLY,sMan,res.getParentDir(),res.getParentsParentId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
      long fileId=sMan.getNextFileId();
      if ((rqArgs.getMode() & GlobalTypes.SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_S_IFIFO.getNumber()) != 0) {
        throw new UserException(POSIXErrno.POSIX_ERROR_EIO,"String_Node_Str");
      }
      String groupId=rq.getDetails().groupIds.get(0);
      int parentMode=faMan.getPosixAccessMode(sMan,res.getParentDir(),rq.getDetails().userId,rq.getDetails().groupIds);
      if ((parentMode & 02000) > 0) {
        groupId=res.getParentDir().getOwningGroupId();
      }
      QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),fileId,rq.getDetails().userId,groupId,0);
      master.getMrcVoucherManager().checkVoucherAvailability(quotaFileInformation);
      file=sMan.createFile(fileId,res.getParentDirId(),res.getFileName(),time,time,time,rq.getDetails().userId,groupId,rqArgs.getMode(),rqArgs.getAttributes(),0,false,0,0,update);
      sMan.setLastFileId(fileId,update);
      createNew=true;
    }
 else     throw exc;
  }
  XLocList xLocList=file.getXLocList();
  XLocSetLock lock=master.getXLocSetCoordinator().getXLocSetLock(file,sMan);
  if (lock.isLocked()) {
    if (lock.hasCrashed()) {
      XLoc[] replicas=new XLoc[xLocList.getReplicaCount()];
      for (int i=0; i < xLocList.getReplicaCount(); i++) {
        replicas[i]=xLocList.getReplica(i);
      }
      xLocList=sMan.createXLocList(replicas,xLocList.getReplUpdatePolicy(),xLocList.getVersion() + 1);
      master.getXLocSetCoordinator().unlockXLocSet(file,sMan,update);
    }
 else {
      throw new UserException(POSIXErrno.POSIX_ERROR_EAGAIN,"String_Node_Str");
    }
  }
  int trEpoch=file.getEpoch();
  if (truncate) {
    file.setIssuedEpoch(file.getIssuedEpoch() + 1);
    trEpoch=file.getIssuedEpoch();
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
  }
  ReplicationPolicy defaultReplPolicy=sMan.getDefaultReplicationPolicy(res.getParentDirId());
  if (defaultReplPolicy == null)   defaultReplPolicy=sMan.getDefaultReplicationPolicy(1);
  boolean replicateOnClose=defaultReplPolicy != null && ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(defaultReplPolicy.getName());
  if ((xLocList == null || xLocList.getReplicaCount() == 0) && (create || write)) {
    boolean singleReplica=defaultReplPolicy == null || ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(defaultReplPolicy.getName()) || replicateOnClose;
    if (singleReplica) {
      XLoc replica=MRCHelper.createReplica(null,sMan,master.getOSDStatusManager(),volume,res.getParentDirId(),p.toString(),((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress(),rqArgs.getCoordinates(),xLocList,0);
      String[] osds=new String[replica.getOSDCount()];
      for (int j=0; j < osds.length; j++)       osds[j]=replica.getOSD(j);
      List<XLoc> repls=new ArrayList<XLoc>();
      repls.add(replica);
      xLocList=sMan.createXLocList(repls.toArray(new XLoc[repls.size()]),ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE,0);
    }
 else {
      int numReplicas=1;
      if (defaultReplPolicy != null)       numReplicas=defaultReplPolicy.getFactor();
      List<XLoc> repls=new ArrayList<XLoc>();
      for (int i=0; i < numReplicas; i++) {
        XLoc replica=MRCHelper.createReplica(null,sMan,master.getOSDStatusManager(),volume,res.getParentDirId(),p.toString(),((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress(),rqArgs.getCoordinates(),xLocList,defaultReplPolicy != null ? defaultReplPolicy.getFlags() : 0);
        String[] osds=new String[replica.getOSDCount()];
        for (int j=0; j < osds.length; j++)         osds[j]=replica.getOSD(j);
        repls.add(replica);
        xLocList=sMan.createXLocList(repls.toArray(new XLoc[repls.size()]),defaultReplPolicy != null ? defaultReplPolicy.getName() : ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE,0);
      }
    }
    file.setXLocList(xLocList);
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
    if (Logging.isDebug())     Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",volume.getId(),file.getId(),xLocList.toString());
  }
  XLocSet.Builder xLocSet=Converter.xLocListToXLocSet(xLocList);
  List<Replica> sortedReplList=master.getOSDStatusManager().getSortedReplicaList(volume.getId(),((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress(),rqArgs.getCoordinates(),xLocSet.getReplicasList(),xLocList).getReplicasList();
  xLocSet.clearReplicas();
  xLocSet.addAllReplicas(sortedReplList);
  xLocSet.setReadOnlyFileSize(file.getSize());
  String globalFileId=MRCHelper.createGlobalFileId(volume,file);
  long expireMs=TimeSync.getGlobalTime() + master.getConfig().getCapabilityTimeout() * 1000;
  String clientID=((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress().getHostAddress();
  long voucherSize=0;
  if (create || truncate || write) {
    QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),file);
    master.getMrcVoucherManager().getVoucher(quotaFileInformation,clientID,expireMs,update);
  }
  Capability cap=new Capability(globalFileId,rqArgs.getFlags(),master.getConfig().getCapabilityTimeout(),TimeSync.getGlobalTime() / 1000 + master.getConfig().getCapabilityTimeout(),clientID,trEpoch,replicateOnClose,!volume.isSnapshotsEnabled() ? SnapConfig.SNAP_CONFIG_SNAPS_DISABLED : volume.isSnapVolume() ? SnapConfig.SNAP_CONFIG_ACCESS_SNAP : SnapConfig.SNAP_CONFIG_ACCESS_CURRENT,volume.getCreationTime(),voucherSize,expireMs,master.getConfig().getCapabilitySecret());
  if (Logging.isDebug())   Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",volume.getId(),file.getId(),cap.toString());
  if (createNew || truncate) {
    MRCHelper.updateFileTimes(res.getParentsParentId(),file,createNew ? !master.getConfig().isNoAtime() : false,true,true,sMan,time,update);
  }
 else   if (!master.getConfig().isNoAtime()) {
    MRCHelper.updateFileTimes(res.getParentsParentId(),file,true,false,false,sMan,time,update);
  }
 else {
    time=0;
  }
  if (createNew)   MRCHelper.updateFileTimes(res.getParentsParentId(),res.getParentDir(),false,true,true,sMan,time,update);
  rq.setResponse(openResponse.newBuilder().setCreds(FileCredentials.newBuilder().setXcap(cap.getXCap()).setXlocs(xLocSet)).setTimestampS(time).build());
  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 openRequest rqArgs=(openRequest)rq.getRequestArgs();
  final VolumeManager vMan=master.getVolumeManager();
  final FileAccessManager faMan=master.getFileAccessManager();
  Path p=new Path(rqArgs.getVolumeName(),rqArgs.getPath());
  StorageManager sMan=vMan.getStorageManagerByName(p.getComp(0));
  PathResolver res=new PathResolver(sMan,p);
  VolumeInfo volume=sMan.getVolumeInfo();
  faMan.checkSearchPermission(sMan,res,rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
  FileMetadata file=null;
  boolean create=(rqArgs.getFlags() & FileAccessManager.O_CREAT) != 0;
  boolean excl=(rqArgs.getFlags() & FileAccessManager.O_EXCL) != 0;
  boolean truncate=(rqArgs.getFlags() & FileAccessManager.O_TRUNC) != 0;
  boolean write=(rqArgs.getFlags() & (FileAccessManager.O_WRONLY | FileAccessManager.O_RDWR)) != 0;
  boolean createNew=false;
  int time=(int)(TimeSync.getGlobalTime() / 1000);
  try {
    res.checkIfFileDoesNotExist();
    if (create && excl)     res.checkIfFileExistsAlready();
    file=res.getFile();
    if (create || truncate || write) {
      QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),file);
      master.getMrcVoucherManager().checkVoucherAvailability(quotaFileInformation);
    }
    if (file.isDirectory() || sMan.getSoftlinkTarget(file.getId()) != null)     throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str");
    if (file.isReadOnly() && ((rqArgs.getFlags() & (FileAccessManager.O_RDWR | FileAccessManager.O_WRONLY | FileAccessManager.O_TRUNC| FileAccessManager.O_APPEND)) != 0))     throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
    faMan.checkPermission(rqArgs.getFlags(),sMan,file,res.getParentDirId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
  }
 catch (  UserException exc) {
    if (exc.getErrno() == POSIXErrno.POSIX_ERROR_ENOENT && create) {
      faMan.checkPermission(FileAccessManager.O_WRONLY,sMan,res.getParentDir(),res.getParentsParentId(),rq.getDetails().userId,rq.getDetails().superUser,rq.getDetails().groupIds);
      long fileId=sMan.getNextFileId();
      if ((rqArgs.getMode() & GlobalTypes.SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_S_IFIFO.getNumber()) != 0) {
        throw new UserException(POSIXErrno.POSIX_ERROR_EIO,"String_Node_Str");
      }
      String groupId=rq.getDetails().groupIds.get(0);
      int parentMode=faMan.getPosixAccessMode(sMan,res.getParentDir(),rq.getDetails().userId,rq.getDetails().groupIds);
      if ((parentMode & 02000) > 0) {
        groupId=res.getParentDir().getOwningGroupId();
      }
      QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),fileId,rq.getDetails().userId,groupId,0);
      master.getMrcVoucherManager().checkVoucherAvailability(quotaFileInformation);
      file=sMan.createFile(fileId,res.getParentDirId(),res.getFileName(),time,time,time,rq.getDetails().userId,groupId,rqArgs.getMode(),rqArgs.getAttributes(),0,false,0,0,update);
      sMan.setLastFileId(fileId,update);
      createNew=true;
    }
 else     throw exc;
  }
  XLocList xLocList=file.getXLocList();
  XLocSetLock lock=master.getXLocSetCoordinator().getXLocSetLock(file,sMan);
  if (lock.isLocked()) {
    if (lock.hasCrashed()) {
      XLoc[] replicas=new XLoc[xLocList.getReplicaCount()];
      for (int i=0; i < xLocList.getReplicaCount(); i++) {
        replicas[i]=xLocList.getReplica(i);
      }
      xLocList=sMan.createXLocList(replicas,xLocList.getReplUpdatePolicy(),xLocList.getVersion() + 1);
      master.getXLocSetCoordinator().unlockXLocSet(file,sMan,update);
    }
 else {
      throw new UserException(POSIXErrno.POSIX_ERROR_EAGAIN,"String_Node_Str");
    }
  }
  int trEpoch=file.getEpoch();
  if (truncate) {
    file.setIssuedEpoch(file.getIssuedEpoch() + 1);
    trEpoch=file.getIssuedEpoch();
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
  }
  ReplicationPolicy defaultReplPolicy=sMan.getDefaultReplicationPolicy(res.getParentDirId());
  if (defaultReplPolicy == null)   defaultReplPolicy=sMan.getDefaultReplicationPolicy(1);
  boolean replicateOnClose=defaultReplPolicy != null && ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(defaultReplPolicy.getName());
  if ((xLocList == null || xLocList.getReplicaCount() == 0) && (create || write)) {
    boolean singleReplica=defaultReplPolicy == null || ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(defaultReplPolicy.getName()) || replicateOnClose;
    if (singleReplica) {
      XLoc replica=MRCHelper.createReplica(null,sMan,master.getOSDStatusManager(),volume,res.getParentDirId(),p.toString(),((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress(),rqArgs.getCoordinates(),xLocList,0);
      String[] osds=new String[replica.getOSDCount()];
      for (int j=0; j < osds.length; j++)       osds[j]=replica.getOSD(j);
      List<XLoc> repls=new ArrayList<XLoc>();
      repls.add(replica);
      xLocList=sMan.createXLocList(repls.toArray(new XLoc[repls.size()]),ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE,0);
    }
 else {
      int numReplicas=1;
      if (defaultReplPolicy != null)       numReplicas=defaultReplPolicy.getFactor();
      List<XLoc> repls=new ArrayList<XLoc>();
      for (int i=0; i < numReplicas; i++) {
        XLoc replica=MRCHelper.createReplica(null,sMan,master.getOSDStatusManager(),volume,res.getParentDirId(),p.toString(),((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress(),rqArgs.getCoordinates(),xLocList,defaultReplPolicy != null ? defaultReplPolicy.getFlags() : 0);
        String[] osds=new String[replica.getOSDCount()];
        for (int j=0; j < osds.length; j++)         osds[j]=replica.getOSD(j);
        repls.add(replica);
        xLocList=sMan.createXLocList(repls.toArray(new XLoc[repls.size()]),defaultReplPolicy != null ? defaultReplPolicy.getName() : ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE,0);
      }
    }
    file.setXLocList(xLocList);
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
    if (Logging.isDebug())     Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",volume.getId(),file.getId(),xLocList.toString());
  }
  XLocSet.Builder xLocSet=Converter.xLocListToXLocSet(xLocList);
  List<Replica> sortedReplList=master.getOSDStatusManager().getSortedReplicaList(volume.getId(),((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress(),rqArgs.getCoordinates(),xLocSet.getReplicasList(),xLocList).getReplicasList();
  xLocSet.clearReplicas();
  xLocSet.addAllReplicas(sortedReplList);
  xLocSet.setReadOnlyFileSize(file.getSize());
  String globalFileId=MRCHelper.createGlobalFileId(volume,file);
  long expireMs=TimeSync.getGlobalTime() + master.getConfig().getCapabilityTimeout() * 1000;
  String clientID=((InetSocketAddress)rq.getRPCRequest().getSenderAddress()).getAddress().getHostAddress();
  long voucherSize=0;
  if (create || truncate || write) {
    QuotaFileInformation quotaFileInformation=new QuotaFileInformation(volume.getId(),file);
    voucherSize=master.getMrcVoucherManager().getVoucher(quotaFileInformation,clientID,expireMs,update);
  }
  Capability cap=new Capability(globalFileId,rqArgs.getFlags(),master.getConfig().getCapabilityTimeout(),TimeSync.getGlobalTime() / 1000 + master.getConfig().getCapabilityTimeout(),clientID,trEpoch,replicateOnClose,!volume.isSnapshotsEnabled() ? SnapConfig.SNAP_CONFIG_SNAPS_DISABLED : volume.isSnapVolume() ? SnapConfig.SNAP_CONFIG_ACCESS_SNAP : SnapConfig.SNAP_CONFIG_ACCESS_CURRENT,volume.getCreationTime(),voucherSize,expireMs,master.getConfig().getCapabilitySecret());
  if (Logging.isDebug())   Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",volume.getId(),file.getId(),cap.toString());
  if (createNew || truncate) {
    MRCHelper.updateFileTimes(res.getParentsParentId(),file,createNew ? !master.getConfig().isNoAtime() : false,true,true,sMan,time,update);
  }
 else   if (!master.getConfig().isNoAtime()) {
    MRCHelper.updateFileTimes(res.getParentsParentId(),file,true,false,false,sMan,time,update);
  }
 else {
    time=0;
  }
  if (createNew)   MRCHelper.updateFileTimes(res.getParentsParentId(),res.getParentDir(),false,true,true,sMan,time,update);
  rq.setResponse(openResponse.newBuilder().setCreds(FileCredentials.newBuilder().setXcap(cap.getXCap()).setXlocs(xLocSet)).setTimestampS(time).build());
  update.execute();
}