Program: 113585
Project: 113585
Buggy source:
@Override public void startRequest(MRCRequest rq) throws Throwable {
  final closeRequest rqArgs=(closeRequest)rq.getRequestArgs();
  Capability cap=new Capability(rqArgs.getWrite_xcap(),master.getConfig().getCapabilitySecret());
  if (!cap.hasValidSignature())   throw new UserException(ErrNo.EPERM,cap + "String_Node_Str");
  if (cap.hasExpired())   throw new UserException(ErrNo.EPERM,cap + "String_Node_Str");
  if (cap.getXCap().getReplicateOnClose()) {
    GlobalFileIdResolver idRes=new GlobalFileIdResolver(cap.getFileId());
    StorageManager sMan=master.getVolumeManager().getStorageManager(idRes.getVolumeId());
    VolumeInfo vol=sMan.getVolumeInfo();
    AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
    FileMetadata file=sMan.getMetadata(idRes.getLocalFileId());
    if (file == null)     throw new UserException(ErrNo.ENOENT,"String_Node_Str" + cap.getFileId() + "String_Node_Str");
    file.setReadOnly(true);
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str");
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str");
    XLocList xLocList=file.getXLocList();
    int replFactor=vol.getAutoReplFactor();
    if (replFactor > xLocList.getReplicaCount()) {
      List<XLoc> repls=new ArrayList<XLoc>();
      for (int i=0; i < xLocList.getReplicaCount(); i++)       repls.add(xLocList.getReplica(i));
      int newVer=xLocList.getVersion() + 1;
      XLoc firstRepl=repls.get(0);
      firstRepl.setReplicationFlags(ReplicationFlags.setReplicaIsComplete(firstRepl.getReplicationFlags()));
      try {
        for (int i=0; i < replFactor - xLocList.getReplicaCount(); i++) {
          int replFlags=ReplicationFlags.setRandomStrategy(0);
          if (vol.getAutoReplFull())           replFlags=ReplicationFlags.setFullReplica(replFlags);
          Replica newRepl=MRCHelper.createReplica(firstRepl.getStripingPolicy(),sMan,master.getOSDStatusManager(),vol,-1,cap.getFileId(),((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress(),xLocList,replFlags);
          String[] osds=newRepl.getOsd_uuids().toArray(new String[newRepl.getOsd_uuids().size()]);
          repls.add(sMan.createXLoc(firstRepl.getStripingPolicy(),osds,newRepl.getReplication_flags()));
          xLocList=sMan.createXLocList(repls.toArray(new XLoc[repls.size()]),Constants.REPL_UPDATE_PC_RONLY,newVer);
        }
      }
 catch (      Exception exc) {
        Logging.logMessage(Logging.LEVEL_WARN,Category.replication,this,"String_Node_Str",file.getId());
        Logging.logMessage(Logging.LEVEL_WARN,Category.replication,this,OutputUtils.stackTraceToString(exc));
      }
      file.setXLocList(xLocList);
    }
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",vol.getAutoReplFactor() - 1);
    XLocSet xLocSet=Converter.xLocListToXLocSet(xLocList);
    xLocSet.setRead_only_file_size(file.getSize());
    rq.getDetails().context=new HashMap<String,Object>();
    rq.getDetails().context.put("String_Node_Str",xLocSet);
    master.getOnCloseReplicationThread().enqueueRequest(rq);
    rq.setResponse(new closeResponse());
    update.execute();
  }
 else {
    rq.setResponse(new closeResponse());
    Logging.logMessage(Logging.LEVEL_WARN,this,"String_Node_Str",cap.toString());
    finishRequest(rq);
  }
}

Fixed version (ground truth):
@Override public void startRequest(MRCRequest rq) throws Throwable {
  final closeRequest rqArgs=(closeRequest)rq.getRequestArgs();
  Capability cap=new Capability(rqArgs.getWrite_xcap(),master.getConfig().getCapabilitySecret());
  if (!cap.hasValidSignature())   throw new UserException(ErrNo.EPERM,cap + "String_Node_Str");
  if (cap.hasExpired())   throw new UserException(ErrNo.EPERM,cap + "String_Node_Str");
  if (cap.getXCap().getReplicateOnClose()) {
    GlobalFileIdResolver idRes=new GlobalFileIdResolver(cap.getFileId());
    StorageManager sMan=master.getVolumeManager().getStorageManager(idRes.getVolumeId());
    VolumeInfo vol=sMan.getVolumeInfo();
    AtomicDBUpdate update=sMan.createAtomicDBUpdate(master,rq);
    FileMetadata file=sMan.getMetadata(idRes.getLocalFileId());
    if (file == null)     throw new UserException(ErrNo.ENOENT,"String_Node_Str" + cap.getFileId() + "String_Node_Str");
    file.setReadOnly(true);
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str");
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str");
    XLocList xLocList=file.getXLocList();
    int replFactor=vol.getAutoReplFactor();
    if (replFactor > xLocList.getReplicaCount()) {
      List<XLoc> repls=new ArrayList<XLoc>();
      for (int i=0; i < xLocList.getReplicaCount(); i++)       repls.add(xLocList.getReplica(i));
      int newVer=xLocList.getVersion() + 1;
      int initialReplCount=xLocList.getReplicaCount();
      XLoc firstRepl=repls.get(0);
      firstRepl.setReplicationFlags(ReplicationFlags.setReplicaIsComplete(firstRepl.getReplicationFlags()));
      try {
        for (int i=0; i < replFactor - initialReplCount; i++) {
          int replFlags=ReplicationFlags.setRandomStrategy(0);
          if (vol.getAutoReplFull())           replFlags=ReplicationFlags.setFullReplica(replFlags);
          Replica newRepl=MRCHelper.createReplica(firstRepl.getStripingPolicy(),sMan,master.getOSDStatusManager(),vol,-1,cap.getFileId(),((InetSocketAddress)rq.getRPCRequest().getClientIdentity()).getAddress(),xLocList,replFlags);
          String[] osds=newRepl.getOsd_uuids().toArray(new String[newRepl.getOsd_uuids().size()]);
          repls.add(sMan.createXLoc(firstRepl.getStripingPolicy(),osds,newRepl.getReplication_flags()));
          xLocList=sMan.createXLocList(repls.toArray(new XLoc[repls.size()]),Constants.REPL_UPDATE_PC_RONLY,newVer);
        }
      }
 catch (      Exception exc) {
        Logging.logMessage(Logging.LEVEL_WARN,Category.replication,this,"String_Node_Str",file.getId());
        Logging.logMessage(Logging.LEVEL_WARN,Category.replication,this,OutputUtils.stackTraceToString(exc));
      }
      file.setXLocList(xLocList);
    }
    sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.replication,this,"String_Node_Str",vol.getAutoReplFactor() - 1);
    XLocSet xLocSet=Converter.xLocListToXLocSet(xLocList);
    xLocSet.setRead_only_file_size(file.getSize());
    rq.getDetails().context=new HashMap<String,Object>();
    rq.getDetails().context.put("String_Node_Str",xLocSet);
    master.getOnCloseReplicationThread().enqueueRequest(rq);
    rq.setResponse(new closeResponse());
    update.execute();
  }
 else {
    rq.setResponse(new closeResponse());
    Logging.logMessage(Logging.LEVEL_WARN,this,"String_Node_Str",cap.toString());
    finishRequest(rq);
  }
}