Program: 113339
Project: 113339
Buggy source:
@Test @Ignore("String_Node_Str") public void testReplicaOpenFile() throws Exception {
  final String VOLUME_NAME=VOLUMENAME + "String_Node_Str";
  Options options=new Options();
  Client client=ClientFactory.createClient(ClientType.NATIVE,dirAddress,userCredentials,null,options);
  client.start();
  String voucherSize="String_Node_Str";
  String voucherSize2X="String_Node_Str";
  String fileSize="String_Node_Str";
  String fileSize2X="String_Node_Str";
  client.createVolume(mrcAddress,auth,userCredentials,VOLUME_NAME);
  Volume volume=client.openVolume(VOLUME_NAME,null,options);
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str",voucherSize,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  boolean error, firstPass;
  String quotaWithVoucher="String_Node_Str";
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str",quotaWithVoucher,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME,quotaWithVoucher,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME,quotaWithVoucher,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  FileHandle fileHandle;
{
    fileHandle=volume.openFile(userCredentials,FILEPATH,SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_TRUNC.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_WRONLY.getNumber(),0777);
    fileHandle.write(userCredentials,getContent(fileSize).getBytes(),Integer.parseInt(fileSize),0);
    fileHandle.close();
  }
  fileHandle=volume.openFile(userCredentials,FILEPATH,SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber());
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
{
    error=false;
    firstPass=false;
    try {
      addReplicas(volume,FILEPATH,1);
      assertEquals(fileSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
      assertEquals(fileSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
      assertEquals(voucherSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
      assertEquals(voucherSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
      firstPass=true;
      addReplicas(volume,FILEPATH,1);
    }
 catch (    PosixErrorException e) {
      if (e.getPosixError().equals(POSIXErrno.POSIX_ERROR_ENOSPC)) {
        error=firstPass;
      }
    }
 finally {
      assertTrue(error);
    }
    Replicas listReplicas=volume.listReplicas(userCredentials,FILEPATH);
    assertEquals(2,listReplicas.getReplicasCount());
    String osdUuid1=listReplicas.getReplicas(0).getOsdUuids(0);
    volume.removeReplica(userCredentials,FILEPATH,osdUuid1);
    assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
    assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
    assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
    assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  }
  fileHandle.close();
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  volume.unlink(userCredentials,FILEPATH);
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  client.deleteVolume(mrcAddress,auth,userCredentials,VOLUME_NAME);
  client.shutdown();
}

Fixed version (ground truth):
@Test public void testReplicaOpenFile() throws Exception {
  final String VOLUME_NAME=VOLUMENAME + "String_Node_Str";
  Options options=new Options();
  Client client=ClientFactory.createClient(ClientType.NATIVE,dirAddress,userCredentials,null,options);
  client.start();
  String voucherSize="String_Node_Str";
  String voucherSize2X="String_Node_Str";
  String fileSize="String_Node_Str";
  String fileSize2X="String_Node_Str";
  client.createVolume(mrcAddress,auth,userCredentials,VOLUME_NAME);
  Volume volume=client.openVolume(VOLUME_NAME,null,options);
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str",voucherSize,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  boolean error, firstPass;
  String quotaWithVoucher="String_Node_Str";
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str",quotaWithVoucher,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME,quotaWithVoucher,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  volume.setXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME,quotaWithVoucher,XATTR_FLAGS.XATTR_FLAGS_CREATE);
  FileHandle fileHandle;
{
    fileHandle=volume.openFile(userCredentials,FILEPATH,SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_TRUNC.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_WRONLY.getNumber(),0777);
    fileHandle.write(userCredentials,getContent(fileSize).getBytes(),Integer.parseInt(fileSize),0);
    fileHandle.close();
  }
  fileHandle=volume.openFile(userCredentials,FILEPATH,SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber());
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
{
    error=false;
    firstPass=false;
    try {
      addReplicas(volume,FILEPATH,1);
      assertEquals(fileSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
      assertEquals(fileSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
      assertEquals(voucherSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
      assertEquals(voucherSize2X,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
      firstPass=true;
      addReplicas(volume,FILEPATH,1);
    }
 catch (    PosixErrorException e) {
      if (e.getPosixError().equals(POSIXErrno.POSIX_ERROR_ENOSPC)) {
        error=firstPass;
      }
    }
 finally {
      assertTrue(error);
    }
    Replicas listReplicas=volume.listReplicas(userCredentials,FILEPATH);
    assertEquals(2,listReplicas.getReplicasCount());
    String osdUuid1=listReplicas.getReplicas(0).getOsdUuids(0);
    volume.removeReplica(userCredentials,FILEPATH,osdUuid1);
    assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
    assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
    assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
    assertEquals(voucherSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  }
  fileHandle.close();
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals(fileSize,volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  volume.unlink(userCredentials,FILEPATH);
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + USERNAME));
  assertEquals("String_Node_Str",volume.getXAttr(userCredentials,"String_Node_Str","String_Node_Str" + GROUPNAME));
  client.deleteVolume(mrcAddress,auth,userCredentials,VOLUME_NAME);
  client.shutdown();
}