Program: 113341
Project: 113341
Buggy source:
private void processWrite(StageRequest rq){
  final WriteObjectCallback cback=(WriteObjectCallback)rq.getCallback();
  try {
    final String fileId=(String)rq.getArgs()[0];
    final long objNo=(Long)rq.getArgs()[1];
    final StripingPolicyImpl sp=(StripingPolicyImpl)rq.getArgs()[2];
    int offset=(Integer)rq.getArgs()[3];
    final ReusableBuffer data=(ReusableBuffer)rq.getArgs()[4];
    final CowPolicy cow=(CowPolicy)rq.getArgs()[5];
    final XLocations xloc=(XLocations)rq.getArgs()[6];
    final boolean gMaxOff=(Boolean)rq.getArgs()[7];
    final boolean syncWrite=(Boolean)rq.getArgs()[8];
    final Long newVersionArg=(Long)rq.getArgs()[9];
    final int dataLength=data.remaining();
    final int stripeSize=sp.getStripeSizeForObject(objNo);
    final FileMetadata fi=layout.getFileMetadata(sp,fileId);
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",fileId,objNo,fi.getLastObjectNumber(),dataLength,offset);
    }
    final int dataCapacity=data.capacity();
    if (offset + dataCapacity > stripeSize) {
      BufferPool.free(data);
      cback.writeComplete(null,ErrorUtils.getErrorResponse(ErrorType.ERRNO,POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + offset + "String_Node_Str"+ dataCapacity+ "String_Node_Str"+ stripeSize+ "String_Node_Str"));
      return;
    }
    cow.initCowFlagsIfRequired(fi.getLastObjectNumber() + 1);
    long largestV=fi.getLargestObjectVersion(objNo);
    final boolean isCow=cow.isCOW((int)objNo);
    long newVersion=(isCow || checksumsEnabled) ? largestV + 1 : Math.max(1,largestV);
    if (newVersionArg != null) {
      newVersion=newVersionArg;
    }
    assert(data != null);
    if (objNo > fi.getLastObjectNumber()) {
      fi.setLastObjectNumber(objNo);
    }
    layout.writeObject(fileId,fi,data,objNo,offset,newVersion,syncWrite,isCow);
    if (cow.cowEnabled() && (isCow || largestV == 0))     layout.updateCurrentObjVersion(fileId,objNo,newVersion);
    if (isCow)     cow.objectChanged((int)objNo);
    OSDWriteResponse.Builder response=OSDWriteResponse.newBuilder();
    if (objNo >= fi.getLastObjectNumber() && !gMaxOff) {
      long newObjSize=dataLength + offset;
      long newFS=0;
      if (objNo > 0) {
        newFS=sp.getObjectEndOffset(objNo - 1) + 1 + newObjSize;
      }
 else {
        newFS=newObjSize;
      }
      if (newFS < fi.getFilesize()) {
        newFS=fi.getFilesize();
      }
      if (newFS > fi.getFilesize() && objNo >= fi.getLastObjectNumber() && objNo >= fi.getGlobalLastObjectNumber()) {
        if (Logging.isDebug())         Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",newFS);
        response.setSizeInBytes(newFS);
        response.setTruncateEpoch((int)fi.getTruncateEpoch());
      }
 else {
        if (Logging.isDebug())         Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",newFS,fi.getFilesize(),fi.getLastObjectNumber(),objNo);
      }
      fi.setFilesize(newFS);
      if (objNo > fi.getLastObjectNumber()) {
        if (objNo > fi.getGlobalLastObjectNumber()) {
          final List<ServiceUUID> osds=xloc.getLocalReplica().getOSDs();
          final ServiceUUID localUUID=master.getConfig().getUUID();
          if (osds.size() > 1) {
            RPCHeader.RequestHeader rqHdr=RPCHeader.RequestHeader.newBuilder().setAuthData(RPCAuthentication.authNone).setUserCreds(RPCAuthentication.userService).setInterfaceId(OSDServiceConstants.INTERFACE_ID).setProcId(OSDServiceConstants.PROC_ID_XTREEMFS_BROADCAST_GMAX).build();
            RPCHeader header=RPCHeader.newBuilder().setCallId(0).setMessageType(MessageType.RPC_REQUEST).setRequestHeader(rqHdr).build();
            xtreemfs_broadcast_gmaxRequest gmaxRq=xtreemfs_broadcast_gmaxRequest.newBuilder().setFileId(fileId).setTruncateEpoch(fi.getTruncateEpoch()).setLastObject(objNo).build();
            for (            ServiceUUID osd : osds) {
              if (!osd.equals(localUUID)) {
                master.sendUDPMessage(header,gmaxRq,osd.getAddress());
              }
            }
          }
        }
      }
    }
    if (Logging.isDebug())     Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",fi.getLastObjectNumber(),fi.getGlobalLastObjectNumber());
    cback.writeComplete(response.build(),null);
  }
 catch (  IOException ex) {
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.storage,this,"String_Node_Str");
    Logging.logError(Logging.LEVEL_ERROR,this,ex);
    cback.writeComplete(null,ErrorUtils.getErrorResponse(ErrorType.ERRNO,POSIXErrno.POSIX_ERROR_EIO,ex.toString()));
  }
}

Fixed version (ground truth):
private void processWrite(StageRequest rq){
  final WriteObjectCallback cback=(WriteObjectCallback)rq.getCallback();
  try {
    final String fileId=(String)rq.getArgs()[0];
    final long objNo=(Long)rq.getArgs()[1];
    final StripingPolicyImpl sp=(StripingPolicyImpl)rq.getArgs()[2];
    int offset=(Integer)rq.getArgs()[3];
    final ReusableBuffer data=(ReusableBuffer)rq.getArgs()[4];
    final CowPolicy cow=(CowPolicy)rq.getArgs()[5];
    final XLocations xloc=(XLocations)rq.getArgs()[6];
    final boolean gMaxOff=(Boolean)rq.getArgs()[7];
    final boolean syncWrite=(Boolean)rq.getArgs()[8];
    final Long newVersionArg=(Long)rq.getArgs()[9];
    final int dataLength=data.remaining();
    final int stripeSize=sp.getStripeSizeForObject(objNo);
    final FileMetadata fi=layout.getFileMetadata(sp,fileId);
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",fileId,objNo,fi.getLastObjectNumber(),dataLength,offset);
    }
    final int dataCapacity=data.capacity();
    if (offset + dataCapacity > stripeSize) {
      BufferPool.free(data);
      cback.writeComplete(null,ErrorUtils.getErrorResponse(ErrorType.ERRNO,POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + offset + "String_Node_Str"+ dataCapacity+ "String_Node_Str"+ stripeSize+ "String_Node_Str"));
      return;
    }
    cow.initCowFlagsIfRequired(fi.getLastObjectNumber() + 1);
    long largestV=fi.getLargestObjectVersion(objNo);
    final boolean isCow=cow.isCOW((int)objNo);
    long newVersion=(isCow || checksumsEnabled) ? largestV + 1 : Math.max(1,largestV);
    if (newVersionArg != null) {
      newVersion=newVersionArg;
    }
    assert(data != null);
    if (objNo > fi.getLastObjectNumber()) {
      fi.setLastObjectNumber(objNo);
    }
    layout.writeObject(fileId,fi,data,objNo,offset,newVersion,syncWrite,isCow);
    if (cow.cowEnabled() && (isCow || largestV == 0))     layout.updateCurrentObjVersion(fileId,objNo,newVersion);
    if (isCow)     cow.objectChanged((int)objNo);
    OSDWriteResponse.Builder response=OSDWriteResponse.newBuilder();
    if (objNo >= fi.getLastObjectNumber()) {
      long newObjSize=dataLength + offset;
      long newFS=0;
      if (objNo > 0) {
        newFS=sp.getObjectEndOffset(objNo - 1) + 1 + newObjSize;
      }
 else {
        newFS=newObjSize;
      }
      if (newFS < fi.getFilesize()) {
        newFS=fi.getFilesize();
      }
      if (newFS > fi.getFilesize() && objNo >= fi.getLastObjectNumber() && objNo >= fi.getGlobalLastObjectNumber()) {
        if (Logging.isDebug())         Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",newFS);
        response.setSizeInBytes(newFS);
        response.setTruncateEpoch((int)fi.getTruncateEpoch());
      }
 else {
        if (Logging.isDebug())         Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",newFS,fi.getFilesize(),fi.getLastObjectNumber(),objNo);
      }
      fi.setFilesize(newFS);
      if (objNo > fi.getLastObjectNumber() && !gMaxOff) {
        if (objNo > fi.getGlobalLastObjectNumber()) {
          final List<ServiceUUID> osds=xloc.getLocalReplica().getOSDs();
          final ServiceUUID localUUID=master.getConfig().getUUID();
          if (osds.size() > 1) {
            RPCHeader.RequestHeader rqHdr=RPCHeader.RequestHeader.newBuilder().setAuthData(RPCAuthentication.authNone).setUserCreds(RPCAuthentication.userService).setInterfaceId(OSDServiceConstants.INTERFACE_ID).setProcId(OSDServiceConstants.PROC_ID_XTREEMFS_BROADCAST_GMAX).build();
            RPCHeader header=RPCHeader.newBuilder().setCallId(0).setMessageType(MessageType.RPC_REQUEST).setRequestHeader(rqHdr).build();
            xtreemfs_broadcast_gmaxRequest gmaxRq=xtreemfs_broadcast_gmaxRequest.newBuilder().setFileId(fileId).setTruncateEpoch(fi.getTruncateEpoch()).setLastObject(objNo).build();
            for (            ServiceUUID osd : osds) {
              if (!osd.equals(localUUID)) {
                master.sendUDPMessage(header,gmaxRq,osd.getAddress());
              }
            }
          }
        }
      }
    }
    if (Logging.isDebug())     Logging.logMessage(Logging.LEVEL_DEBUG,Category.proc,this,"String_Node_Str",fi.getLastObjectNumber(),fi.getGlobalLastObjectNumber());
    cback.writeComplete(response.build(),null);
  }
 catch (  IOException ex) {
    Logging.logMessage(Logging.LEVEL_DEBUG,Category.storage,this,"String_Node_Str");
    Logging.logError(Logging.LEVEL_ERROR,this,ex);
    cback.writeComplete(null,ErrorUtils.getErrorResponse(ErrorType.ERRNO,POSIXErrno.POSIX_ERROR_EIO,ex.toString()));
  }
}