Program: 113643
Project: 113643
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 int dataLength=data.remaining();
    final int stripeSize=sp.getStripeSizeForObject(objNo);
    final FileInfo fi=layout.getFileInfo(sp,fileId);
    final long oldChecksum=fi.getObjectChecksum(objNo);
    final boolean rangeRequested=(offset > 0) || (data.capacity() < stripeSize);
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fileId + "String_Node_Str"+ objNo+ "String_Node_Str"+ "String_Node_Str"+ fi.getLastObjectNumber()+ "String_Node_Str"+ dataLength+ "String_Node_Str"+ offset);
    }
    if (offset + data.capacity() > stripeSize) {
      BufferPool.free(data);
      cback.writeComplete(null,new OSDException(ErrorCodes.INVALID_PARAMS,"String_Node_Str","String_Node_Str"));
      return;
    }
    int currentV=fi.getObjectVersion(objNo);
    if (currentV == 0) {
      currentV++;
    }
    int nextV=currentV;
    assert(data != null);
    ReusableBuffer writeData=data;
    if (cow.isCOW((int)objNo)) {
      nextV++;
      if (Logging.isDebug()) {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fileId + "String_Node_Str"+ objNo+ "String_Node_Str"+ nextV);
      }
      if (rangeRequested) {
        ObjectInformation obj=layout.readObject(fileId,objNo,currentV,oldChecksum,sp);
        ObjectData oldObject=obj.getObjectData(fi.getLastObjectNumber() == objNo,0,sp.getStripeSizeForObject(objNo));
        if (oldObject.getData() == null) {
          if (oldObject.getZero_padding() > 0) {
            writeData=BufferPool.allocate(stripeSize);
            for (int i=0; i < stripeSize; i++) {
              writeData.put((byte)0);
            }
            writeData.position(offset);
            writeData.put(data);
            writeData.position(0);
            BufferPool.free(data);
          }
 else {
            if (offset > 0) {
              writeData=BufferPool.allocate(offset + data.capacity());
              for (int i=0; i < offset; i++) {
                writeData.put((byte)0);
              }
              writeData.put(data);
              writeData.position(0);
              BufferPool.free(data);
            }
 else {
              writeData=data;
            }
          }
        }
 else {
          if (oldObject.getData().capacity() >= offset + data.capacity()) {
            writeData=oldObject.getData();
            writeData.position(offset);
            writeData.put(data);
            BufferPool.free(data);
          }
 else {
            writeData=BufferPool.allocate(offset + data.capacity());
            writeData.put(oldObject.getData());
            BufferPool.free(oldObject.getData());
            writeData.position(offset);
            writeData.put(data);
            BufferPool.free(data);
          }
        }
      }
      offset=0;
      cow.objectChanged((int)objNo);
    }
    writeData.position(0);
    layout.writeObject(fileId,objNo,writeData,nextV,offset,oldChecksum,sp);
    long newChecksum=layout.createChecksum(fileId,objNo,writeData.capacity() == sp.getStripeSizeForObject(objNo) ? writeData : null,nextV,oldChecksum);
    fi.getObjVersions().put(objNo,nextV);
    fi.getObjChecksums().put(objNo,newChecksum);
    OSDWriteResponse response=new OSDWriteResponse();
    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() && objNo >= fi.getLastObjectNumber() && objNo >= fi.getGlobalLastObjectNumber()) {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + newFS);
        response.getNew_file_size().add(new NewFileSize(newFS,(int)fi.getTruncateEpoch()));
      }
 else {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + newFS + "String_Node_Str"+ fi.getFilesize()+ "String_Node_Str"+ fi.getLastObjectNumber()+ "String_Node_Str"+ objNo);
      }
      fi.setFilesize(newFS);
      if (objNo > fi.getLastObjectNumber()) {
        fi.setLastObjectNumber(objNo);
        if (objNo > fi.getGlobalLastObjectNumber()) {
          final List<ServiceUUID> osds=xloc.getLocalReplica().getOSDs();
          final ServiceUUID localUUID=master.getConfig().getUUID();
          if (osds.size() > 1) {
            for (            ServiceUUID osd : osds) {
              if (!osd.equals(localUUID)) {
                final GMAXMessage m=new GMAXMessage(fileId,fi.getTruncateEpoch(),objNo);
                master.getUdpComStage().send(m.getMessage(osd.getAddress()));
              }
            }
          }
        }
      }
    }
    Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fi.getLastObjectNumber() + "String_Node_Str"+ fi.getGlobalLastObjectNumber());
    BufferPool.free(writeData);
    cback.writeComplete(response,null);
  }
 catch (  IOException ex) {
    ex.printStackTrace();
    cback.writeComplete(null,ex);
  }
}

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 int dataLength=data.remaining();
    final int stripeSize=sp.getStripeSizeForObject(objNo);
    final FileInfo fi=layout.getFileInfo(sp,fileId);
    final long oldChecksum=fi.getObjectChecksum(objNo);
    final boolean rangeRequested=(offset > 0) || (data.capacity() < stripeSize);
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fileId + "String_Node_Str"+ objNo+ "String_Node_Str"+ "String_Node_Str"+ fi.getLastObjectNumber()+ "String_Node_Str"+ dataLength+ "String_Node_Str"+ offset);
    }
    final int dataCapacity=data.capacity();
    if (offset + dataCapacity > stripeSize) {
      BufferPool.free(data);
      cback.writeComplete(null,new OSDException(ErrorCodes.INVALID_PARAMS,"String_Node_Str" + offset + "String_Node_Str"+ dataCapacity+ "String_Node_Str"+ stripeSize+ "String_Node_Str","String_Node_Str"));
      return;
    }
    int currentV=fi.getObjectVersion(objNo);
    if (currentV == 0) {
      currentV++;
    }
    int nextV=currentV;
    assert(data != null);
    ReusableBuffer writeData=data;
    if (cow.isCOW((int)objNo)) {
      nextV++;
      if (Logging.isDebug()) {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fileId + "String_Node_Str"+ objNo+ "String_Node_Str"+ nextV);
      }
      if (rangeRequested) {
        ObjectInformation obj=layout.readObject(fileId,objNo,currentV,oldChecksum,sp);
        ObjectData oldObject=obj.getObjectData(fi.getLastObjectNumber() == objNo,0,sp.getStripeSizeForObject(objNo));
        if (oldObject.getData() == null) {
          if (oldObject.getZero_padding() > 0) {
            writeData=BufferPool.allocate(stripeSize);
            for (int i=0; i < stripeSize; i++) {
              writeData.put((byte)0);
            }
            writeData.position(offset);
            writeData.put(data);
            writeData.position(0);
            BufferPool.free(data);
          }
 else {
            if (offset > 0) {
              writeData=BufferPool.allocate(offset + data.capacity());
              for (int i=0; i < offset; i++) {
                writeData.put((byte)0);
              }
              writeData.put(data);
              writeData.position(0);
              BufferPool.free(data);
            }
 else {
              writeData=data;
            }
          }
        }
 else {
          if (oldObject.getData().capacity() >= offset + data.capacity()) {
            writeData=oldObject.getData();
            writeData.position(offset);
            writeData.put(data);
            BufferPool.free(data);
          }
 else {
            writeData=BufferPool.allocate(offset + data.capacity());
            writeData.put(oldObject.getData());
            BufferPool.free(oldObject.getData());
            writeData.position(offset);
            writeData.put(data);
            BufferPool.free(data);
          }
        }
      }
      offset=0;
      cow.objectChanged((int)objNo);
    }
    writeData.position(0);
    layout.writeObject(fileId,objNo,writeData,nextV,offset,oldChecksum,sp);
    long newChecksum=layout.createChecksum(fileId,objNo,writeData.capacity() == sp.getStripeSizeForObject(objNo) ? writeData : null,nextV,oldChecksum);
    fi.getObjVersions().put(objNo,nextV);
    fi.getObjChecksums().put(objNo,newChecksum);
    OSDWriteResponse response=new OSDWriteResponse();
    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() && objNo >= fi.getLastObjectNumber() && objNo >= fi.getGlobalLastObjectNumber()) {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + newFS);
        response.getNew_file_size().add(new NewFileSize(newFS,(int)fi.getTruncateEpoch()));
      }
 else {
        Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + newFS + "String_Node_Str"+ fi.getFilesize()+ "String_Node_Str"+ fi.getLastObjectNumber()+ "String_Node_Str"+ objNo);
      }
      fi.setFilesize(newFS);
      if (objNo > fi.getLastObjectNumber()) {
        fi.setLastObjectNumber(objNo);
        if (objNo > fi.getGlobalLastObjectNumber()) {
          final List<ServiceUUID> osds=xloc.getLocalReplica().getOSDs();
          final ServiceUUID localUUID=master.getConfig().getUUID();
          if (osds.size() > 1) {
            for (            ServiceUUID osd : osds) {
              if (!osd.equals(localUUID)) {
                final GMAXMessage m=new GMAXMessage(fileId,fi.getTruncateEpoch(),objNo);
                master.getUdpComStage().send(m.getMessage(osd.getAddress()));
              }
            }
          }
        }
      }
    }
    Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fi.getLastObjectNumber() + "String_Node_Str"+ fi.getGlobalLastObjectNumber());
    BufferPool.free(writeData);
    cback.writeComplete(response,null);
  }
 catch (  IOException ex) {
    ex.printStackTrace();
    cback.writeComplete(null,ex);
  }
}