Program: 113597
Project: 113597
Buggy source:
@Override public void startRequest(MRCRequest rq) throws Throwable {
  final openRequest rqArgs=(openRequest)rq.getRequestArgs();
  final VolumeManager vMan=master.getVolumeManager();
  final FileAccessManager faMan=master.getFileAccessManager();
  Path p=new Path(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;
  try {
    res.checkIfFileDoesNotExist();
    if (create && excl)     res.checkIfFileExistsAlready();
    file=res.getFile();
    String target=sMan.getSoftlinkTarget(file.getId());
    if (target != null) {
      rqArgs.setPath(target);
      p=new Path(target);
      if (!vMan.hasVolume(p.getComp(0))) {
        finishRequest(rq,new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrNo.ENOENT,"String_Node_Str" + target + "String_Node_Str"));
        return;
      }
      sMan=vMan.getStorageManagerByName(p.getComp(0));
      volume=sMan.getVolumeInfo();
      res=new PathResolver(sMan,p);
      file=res.getFile();
    }
    if (file.isDirectory())     throw new UserException(ErrNo.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(ErrNo.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() == ErrNo.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();
      int time=(int)(TimeSync.getGlobalTime() / 1000);
      file=sMan.createFile(fileId,res.getParentDirId(),res.getFileName(),time,time,time,rq.getDetails().userId,rq.getDetails().groupIds.get(0),rqArgs.getMode(),rqArgs.getAttributes(),0,false,0,0,update);
      sMan.setLastFileId(fileId,update);
      createNew=true;
    }
 else     throw exc;
  }
  int trEpoch=file.getEpoch();
  if (truncate) {
    file.setIssuedEpoch(file.getIssuedEpoch() + 1);
    trEpoch=file.getIssuedEpoch();
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
  }
  XLocList xLocList=file.getXLocList();
  XLocSet xLocSet=null;
  if (xLocList == null || xLocList.getReplicaCount() == 0) {
    Replica replica=MRCHelper.createReplica(null,sMan,master.getOSDStatusManager(),volume,res.getParentDirId(),rqArgs.getPath(),((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress(),xLocList,0);
    ReplicaSet replicas=new ReplicaSet();
    replicas.add(replica);
    xLocSet=new XLocSet(replicas,0,file.isReadOnly() ? Constants.REPL_UPDATE_PC_RONLY : Constants.REPL_UPDATE_PC_NONE,0);
    xLocList=Converter.xLocSetToXLocList(sMan,xLocSet);
    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(),xLocSet.toString());
  }
 else {
    xLocSet=Converter.xLocListToXLocSet(xLocList);
    if (file.isReadOnly())     xLocSet.setRead_only_file_size(file.getSize());
  }
  boolean replicateOnClose=volume.getAutoReplFactor() > 1;
  xLocSet.setReplicas(master.getOSDStatusManager().getSortedReplicaList(volume.getId(),((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress(),xLocList));
  Capability cap=new Capability(volume.getId() + "String_Node_Str" + file.getId(),rqArgs.getFlags(),TimeSync.getGlobalTime() / 1000 + Capability.DEFAULT_VALIDITY,((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress().getHostAddress(),trEpoch,replicateOnClose,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,update);
 else   if (write)   MRCHelper.updateFileTimes(res.getParentsParentId(),file,false,true,true,sMan,update);
 else   if (!master.getConfig().isNoAtime())   MRCHelper.updateFileTimes(res.getParentsParentId(),file,true,false,false,sMan,update);
  if (createNew)   MRCHelper.updateFileTimes(res.getParentsParentId(),res.getParentDir(),false,true,true,sMan,update);
  rq.setResponse(new openResponse(new FileCredentials(xLocSet,cap.getXCap())));
  update.execute();
}

Fixed version (ground truth):
@Override public void startRequest(MRCRequest rq) throws Throwable {
  final openRequest rqArgs=(openRequest)rq.getRequestArgs();
  final VolumeManager vMan=master.getVolumeManager();
  final FileAccessManager faMan=master.getFileAccessManager();
  Path p=new Path(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;
  try {
    res.checkIfFileDoesNotExist();
    if (create && excl)     res.checkIfFileExistsAlready();
    file=res.getFile();
    String target=sMan.getSoftlinkTarget(file.getId());
    if (target != null) {
      rqArgs.setPath(target);
      p=new Path(target);
      if (!vMan.hasVolume(p.getComp(0))) {
        finishRequest(rq,new ErrorRecord(ErrorClass.USER_EXCEPTION,ErrNo.ENOENT,"String_Node_Str" + target + "String_Node_Str"));
        return;
      }
      sMan=vMan.getStorageManagerByName(p.getComp(0));
      volume=sMan.getVolumeInfo();
      res=new PathResolver(sMan,p);
      file=res.getFile();
    }
    if (file.isDirectory())     throw new UserException(ErrNo.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(ErrNo.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() == ErrNo.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();
      int time=(int)(TimeSync.getGlobalTime() / 1000);
      file=sMan.createFile(fileId,res.getParentDirId(),res.getFileName(),time,time,time,rq.getDetails().userId,rq.getDetails().groupIds.get(0),rqArgs.getMode(),rqArgs.getAttributes(),0,false,0,0,update);
      sMan.setLastFileId(fileId,update);
      createNew=true;
    }
 else     throw exc;
  }
  int trEpoch=file.getEpoch();
  if (truncate) {
    file.setIssuedEpoch(file.getIssuedEpoch() + 1);
    trEpoch=file.getIssuedEpoch();
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
  }
  XLocList xLocList=file.getXLocList();
  XLocSet xLocSet=null;
  if ((xLocList == null || xLocList.getReplicaCount() == 0) && (create || write)) {
    Replica replica=MRCHelper.createReplica(null,sMan,master.getOSDStatusManager(),volume,res.getParentDirId(),rqArgs.getPath(),((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress(),xLocList,0);
    ReplicaSet replicas=new ReplicaSet();
    replicas.add(replica);
    xLocSet=new XLocSet(replicas,0,file.isReadOnly() ? Constants.REPL_UPDATE_PC_RONLY : Constants.REPL_UPDATE_PC_NONE,0);
    xLocList=Converter.xLocSetToXLocList(sMan,xLocSet);
    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(),xLocSet.toString());
  }
 else {
    xLocSet=Converter.xLocListToXLocSet(xLocList);
    if (file.isReadOnly())     xLocSet.setRead_only_file_size(file.getSize());
  }
  boolean replicateOnClose=volume.getAutoReplFactor() > 1;
  xLocSet.setReplicas(master.getOSDStatusManager().getSortedReplicaList(volume.getId(),((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress(),xLocList));
  Capability cap=new Capability(volume.getId() + "String_Node_Str" + file.getId(),rqArgs.getFlags(),TimeSync.getGlobalTime() / 1000 + Capability.DEFAULT_VALIDITY,((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress().getHostAddress(),trEpoch,replicateOnClose,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,update);
 else   if (write)   MRCHelper.updateFileTimes(res.getParentsParentId(),file,false,true,true,sMan,update);
 else   if (!master.getConfig().isNoAtime())   MRCHelper.updateFileTimes(res.getParentsParentId(),file,true,false,false,sMan,update);
  if (createNew)   MRCHelper.updateFileTimes(res.getParentsParentId(),res.getParentDir(),false,true,true,sMan,update);
  rq.setResponse(new openResponse(new FileCredentials(xLocSet,cap.getXCap())));
  update.execute();
}