Program: 113664
Project: 113664
Buggy source:
public void testReplicaCreationAndRemoval() throws Exception {
  randomAccessFile=new RandomAccessFile("String_Node_Str",mrc1Address,volumeName + "String_Node_Str",testEnv.getRpcClient(),userID,groupIDs);
  byte[] bytesIn=new String("String_Node_Str").getBytes();
  int length=bytesIn.length;
  ReusableBuffer data=ReusableBuffer.wrap(bytesIn);
  randomAccessFile.writeObject(0,0,data);
  randomAccessFile.setReadOnly(true);
  assertEquals(Constants.REPL_UPDATE_PC_RONLY,randomAccessFile.getCredentials().getXlocs().getRepUpdatePolicy());
  List<ServiceUUID> replica1=randomAccessFile.getSuitableOSDs();
  for (int i=0; i < replica1.size(); i++) {
    if (i >= randomAccessFile.getStripingPolicy().getWidth())     replica1.remove(i);
  }
  randomAccessFile.addReplica(replica1,randomAccessFile.getStripingPolicy());
  assertEquals(2,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  List<ServiceUUID> replica2=randomAccessFile.getSuitableOSDs();
  for (int i=0; i < replica1.size(); i++) {
    if (i >= randomAccessFile.getStripingPolicy().getWidth())     replica1.remove(i);
  }
  randomAccessFile.addReplica(replica2,randomAccessFile.getStripingPolicy());
  assertEquals(3,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  randomAccessFile.removeReplica(replica1.get(0));
  assertEquals(2,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  try {
    randomAccessFile.setReadOnly(false);
    fail("String_Node_Str");
  }
 catch (  Exception e) {
  }
  randomAccessFile.removeReplica(replica2.get(0));
  assertEquals(1,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  try {
    randomAccessFile.setReadOnly(false);
  }
 catch (  Exception e) {
    fail("String_Node_Str");
  }
}

Fixed version (ground truth):
public void testReplicaCreationAndRemoval() throws Exception {
  randomAccessFile=new RandomAccessFile("String_Node_Str",mrc1Address,volumeName + "String_Node_Str",testEnv.getRpcClient(),userID,groupIDs);
  byte[] bytesIn=new String("String_Node_Str").getBytes();
  int length=bytesIn.length;
  ReusableBuffer data=ReusableBuffer.wrap(bytesIn);
  randomAccessFile.writeObject(0,0,data);
  randomAccessFile.setReadOnly(true);
  assertEquals(Constants.REPL_UPDATE_PC_RONLY,randomAccessFile.getCredentials().getXlocs().getRepUpdatePolicy());
  List<ServiceUUID> replica1=randomAccessFile.getSuitableOSDsForAReplica();
  replica1=replica1.subList(0,randomAccessFile.getStripingPolicy().getWidth());
  randomAccessFile.addReplica(replica1,randomAccessFile.getStripingPolicy());
  assertEquals(2,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  List<ServiceUUID> replica2=randomAccessFile.getSuitableOSDsForAReplica();
  replica2=replica2.subList(0,randomAccessFile.getStripingPolicy().getWidth());
  randomAccessFile.addReplica(replica2,randomAccessFile.getStripingPolicy());
  assertEquals(3,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  randomAccessFile.removeReplica(replica1.get(0));
  assertEquals(2,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  try {
    randomAccessFile.setReadOnly(false);
    fail("String_Node_Str");
  }
 catch (  Exception e) {
  }
  randomAccessFile.removeReplica(replica2.get(0));
  assertEquals(1,randomAccessFile.getCredentials().getXlocs().getReplicas().size());
  try {
    randomAccessFile.setReadOnly(false);
  }
 catch (  Exception e) {
    fail("String_Node_Str");
  }
}