Program: 113529
Project: 113529
Buggy source:
public void testInterleavedWriteAndTruncate() throws Exception {
  final int numIterations=20;
  final int maxObject=20;
  final int maxSize=maxObject * SIZE;
  final int numWrittenObjs=5;
  final MRCDummy mrcDummy=new MRCDummy(capSecret);
  for (int k=0; k < 3; k++) {
    final FileCredentials fcred=new FileCredentials(getCap(FILE_ID).getXCap(),xloc);
    final List<RPCResponse> responses=new LinkedList<RPCResponse>();
    for (int l=0; l < numIterations; l++) {
      for (int i=0; i < numWrittenObjs; i++) {
        final int objId=(int)(Math.random() * maxObject);
        final int osdIndex=objId % osdIDs.size();
        final int size=(int)((SIZE - 1) * Math.random()) + 1;
        ObjectData objdata=new ObjectData(0,false,0,SetupUtils.generateData(size));
        RPCResponse<OSDWriteResponse> r=client.write(osdIDs.get(osdIndex).getAddress(),FILE_ID,fcred,objId,0,0,0,objdata);
        responses.add(r);
        r.registerListener(mrcDummy);
      }
      for (      RPCResponse r : responses) {
        r.waitForResult();
        r.freeBuffers();
      }
      responses.clear();
      fcred.setXcap(mrcDummy.open('t').getXCap());
      long newSize=(long)(Math.random() * maxSize);
      RPCResponse<OSDWriteResponse> rt=client.truncate(osdIDs.get(0).getAddress(),FILE_ID,fcred,newSize);
      rt.registerListener(mrcDummy);
      rt.waitForResult();
      rt.freeBuffers();
      long fileSize=mrcDummy.getFileSize();
      for (int i=0; i < maxObject; i++) {
        RPCResponse<ObjectData> r2=client.read(osdIDs.get(i % osdIDs.size()).getAddress(),FILE_ID,fcred,i,0,0,SIZE);
        ObjectData result=r2.get();
        r2.freeBuffers();
        if (i < fileSize / SIZE)         assertEquals(SIZE,result.getZero_padding() + result.getData().capacity());
 else         if (i == fileSize / SIZE) {
          if (fileSize % SIZE == 0)           assertEquals(0,result.getZero_padding() + result.getData().capacity());
 else           assertEquals(fileSize % SIZE,result.getZero_padding() + result.getData().capacity());
        }
 else         assertEquals(0,result.getZero_padding() + result.getData().capacity());
        BufferPool.free(result.getData());
      }
    }
    if (k != 2)     Thread.sleep(90000);
  }
}

Fixed version (ground truth):
public void testInterleavedWriteAndTruncate() throws Exception {
  final int numIterations=20;
  final int maxObject=20;
  final int maxSize=maxObject * SIZE;
  final int numWrittenObjs=5;
  final MRCDummy mrcDummy=new MRCDummy(capSecret);
  for (int k=0; k < 3; k++) {
    final FileCredentials fcred=new FileCredentials(getCap(FILE_ID).getXCap(),xloc);
    final List<RPCResponse> responses=new LinkedList<RPCResponse>();
    for (int l=0; l < numIterations; l++) {
      for (int i=0; i < numWrittenObjs; i++) {
        final int objId=(int)(Math.random() * maxObject);
        final int osdIndex=objId % osdIDs.size();
        final int size=(int)((SIZE - 1) * Math.random()) + 1;
        ObjectData objdata=new ObjectData(0,false,0,SetupUtils.generateData(size));
        RPCResponse<OSDWriteResponse> r=client.write(osdIDs.get(osdIndex).getAddress(),FILE_ID,fcred,objId,0,0,0,objdata);
        responses.add(r);
        r.registerListener(mrcDummy);
      }
      for (      RPCResponse r : responses) {
        r.waitForResult();
        r.freeBuffers();
      }
      responses.clear();
      fcred.setXcap(mrcDummy.open('t').getXCap());
      long newSize=(long)(Math.random() * maxSize);
      RPCResponse<OSDWriteResponse> rt=client.truncate(osdIDs.get(0).getAddress(),FILE_ID,fcred,newSize);
      rt.registerListener(mrcDummy);
      rt.waitForResult();
      rt.freeBuffers();
      long fileSize=mrcDummy.getFileSize();
      for (int i=0; i < maxObject; i++) {
        RPCResponse<ObjectData> r2=client.read(osdIDs.get(i % osdIDs.size()).getAddress(),FILE_ID,fcred,i,0,0,SIZE);
        ObjectData result=r2.get();
        r2.freeBuffers();
        if (i < fileSize / SIZE)         assertEquals(SIZE,result.getZero_padding() + result.getData().capacity());
 else         if (i == fileSize / SIZE) {
          if (fileSize % SIZE == 0)           assertEquals(0,result.getZero_padding() + result.getData().capacity());
 else           assertEquals(fileSize % SIZE,result.getZero_padding() + result.getData().capacity());
        }
 else         assertEquals(0,result.getZero_padding() + result.getData().capacity());
        BufferPool.free(result.getData());
      }
    }
    if (k != 2) {
      System.out.println("String_Node_Str");
      Thread.sleep(61000);
    }
  }
}