nus-yam/ex-repair huggingface dataset:
Program: 106147
Project: 106147
Buggy source:
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,String name,KVMStoragePool destPool){
  StorageAdaptor adaptor=getStorageAdaptor(destPool.getType());
  if (destPool.getType() == StoragePoolType.RBD) {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.RAW,template.getSize(),destPool);
  }
 else   if (destPool.getType() == StoragePoolType.CLVM) {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.RAW,template.getSize(),destPool);
  }
 else   if (template.getFormat() == PhysicalDiskFormat.DIR) {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.DIR,template.getSize(),destPool);
  }
 else {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.QCOW2,template.getSize(),destPool);
  }
}

Fixed version (ground truth):
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,String name,KVMStoragePool destPool,int timeout){
  StorageAdaptor adaptor=getStorageAdaptor(destPool.getType());
  if (destPool.getType() == StoragePoolType.RBD) {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.RAW,template.getSize(),destPool,timeout);
  }
 else   if (destPool.getType() == StoragePoolType.CLVM) {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.RAW,template.getSize(),destPool,timeout);
  }
 else   if (template.getFormat() == PhysicalDiskFormat.DIR) {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.DIR,template.getSize(),destPool,timeout);
  }
 else {
    return adaptor.createDiskFromTemplate(template,name,PhysicalDiskFormat.QCOW2,template.getSize(),destPool,timeout);
  }
}
Program: 106148
Project: 106148
Buggy source:
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk,String name,KVMStoragePool destPool){
  StorageAdaptor adaptor=getStorageAdaptor(destPool.getType());
  return adaptor.copyPhysicalDisk(disk,name,destPool);
}

Fixed version (ground truth):
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk,String name,KVMStoragePool destPool,int timeout){
  StorageAdaptor adaptor=getStorageAdaptor(destPool.getType());
  return adaptor.copyPhysicalDisk(disk,name,destPool,timeout);
}
Program: 106150
Project: 106150
Buggy source:
private KVMPhysicalDisk templateToPrimaryDownload(String templateUrl,KVMStoragePool primaryPool){
  int index=templateUrl.lastIndexOf("String_Node_Str");
  String mountpoint=templateUrl.substring(0,index);
  String templateName=null;
  if (index < templateUrl.length() - 1) {
    templateName=templateUrl.substring(index + 1);
  }
  KVMPhysicalDisk templateVol=null;
  KVMStoragePool secondaryPool=null;
  try {
    secondaryPool=storagePoolMgr.getStoragePoolByURI(mountpoint);
    if (templateName == null) {
      secondaryPool.refresh();
      List<KVMPhysicalDisk> disks=secondaryPool.listPhysicalDisks();
      if (disks == null || disks.isEmpty()) {
        s_logger.error("String_Node_Str" + secondaryPool.getUuid());
        return null;
      }
      for (      KVMPhysicalDisk disk : disks) {
        if (disk.getName().endsWith("String_Node_Str")) {
          templateVol=disk;
          break;
        }
      }
      if (templateVol == null) {
        s_logger.error("String_Node_Str" + secondaryPool.getUuid());
        return null;
      }
    }
 else {
      templateVol=secondaryPool.getPhysicalDisk(templateName);
    }
    KVMPhysicalDisk primaryVol=storagePoolMgr.copyPhysicalDisk(templateVol,UUID.randomUUID().toString(),primaryPool);
    return primaryVol;
  }
 catch (  CloudRuntimeException e) {
    s_logger.error("String_Node_Str",e);
    return null;
  }
 finally {
    if (secondaryPool != null) {
      secondaryPool.delete();
    }
  }
}

Fixed version (ground truth):
private KVMPhysicalDisk templateToPrimaryDownload(String templateUrl,KVMStoragePool primaryPool,int timeout){
  int index=templateUrl.lastIndexOf("String_Node_Str");
  String mountpoint=templateUrl.substring(0,index);
  String templateName=null;
  if (index < templateUrl.length() - 1) {
    templateName=templateUrl.substring(index + 1);
  }
  KVMPhysicalDisk templateVol=null;
  KVMStoragePool secondaryPool=null;
  try {
    secondaryPool=storagePoolMgr.getStoragePoolByURI(mountpoint);
    if (templateName == null) {
      secondaryPool.refresh();
      List<KVMPhysicalDisk> disks=secondaryPool.listPhysicalDisks();
      if (disks == null || disks.isEmpty()) {
        s_logger.error("String_Node_Str" + secondaryPool.getUuid());
        return null;
      }
      for (      KVMPhysicalDisk disk : disks) {
        if (disk.getName().endsWith("String_Node_Str")) {
          templateVol=disk;
          break;
        }
      }
      if (templateVol == null) {
        s_logger.error("String_Node_Str" + secondaryPool.getUuid());
        return null;
      }
    }
 else {
      templateVol=secondaryPool.getPhysicalDisk(templateName);
    }
    KVMPhysicalDisk primaryVol=storagePoolMgr.copyPhysicalDisk(templateVol,UUID.randomUUID().toString(),primaryPool,timeout);
    return primaryVol;
  }
 catch (  CloudRuntimeException e) {
    s_logger.error("String_Node_Str",e);
    return null;
  }
 finally {
    if (secondaryPool != null) {
      secondaryPool.delete();
    }
  }
}
Program: 106153
Project: 106153
Buggy source:
protected Answer backupSnapshotForObjectStore(CopyCommand cmd){
  DataTO srcData=cmd.getSrcTO();
  DataTO destData=cmd.getDestTO();
  SnapshotObjectTO snapshot=(SnapshotObjectTO)srcData;
  DataStoreTO imageStore=destData.getDataStore();
  DataTO cacheData=cmd.getCacheTO();
  if (cacheData == null) {
    return new CopyCmdAnswer("String_Node_Str");
  }
  DataStoreTO cacheStore=cacheData.getDataStore();
  ((SnapshotObjectTO)destData).setDataStore(cacheStore);
  CopyCmdAnswer answer=(CopyCmdAnswer)backupSnapshot(cmd);
  if (!answer.getResult()) {
    return answer;
  }
  SnapshotObjectTO snapshotOnCacheStore=(SnapshotObjectTO)answer.getNewData();
  snapshotOnCacheStore.setDataStore(cacheStore);
  ((SnapshotObjectTO)destData).setDataStore(imageStore);
  CopyCommand newCpyCmd=new CopyCommand(snapshotOnCacheStore,destData,cmd.getWait(),cmd.executeInSequence());
  return copyToObjectStore(newCpyCmd);
}

Fixed version (ground truth):
protected Answer backupSnapshotForObjectStore(CopyCommand cmd){
  DataTO srcData=cmd.getSrcTO();
  DataTO destData=cmd.getDestTO();
  SnapshotObjectTO snapshot=(SnapshotObjectTO)srcData;
  DataStoreTO imageStore=destData.getDataStore();
  DataTO cacheData=cmd.getCacheTO();
  if (cacheData == null) {
    return new CopyCmdAnswer("String_Node_Str");
  }
  DataStoreTO cacheStore=cacheData.getDataStore();
  ((SnapshotObjectTO)destData).setDataStore(cacheStore);
  CopyCmdAnswer answer=(CopyCmdAnswer)backupSnapshot(cmd);
  if (!answer.getResult()) {
    return answer;
  }
  SnapshotObjectTO snapshotOnCacheStore=(SnapshotObjectTO)answer.getNewData();
  snapshotOnCacheStore.setDataStore(cacheStore);
  ((SnapshotObjectTO)destData).setDataStore(imageStore);
  CopyCommand newCpyCmd=new CopyCommand(snapshotOnCacheStore,destData,cmd.getWaitInMillSeconds(),cmd.executeInSequence());
  return copyToObjectStore(newCpyCmd);
}
Program: 106160
Project: 106160
Buggy source:
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,String name,PhysicalDiskFormat format,long size,KVMStoragePool destPool);

Fixed version (ground truth):
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,String name,PhysicalDiskFormat format,long size,KVMStoragePool destPool,int timeout);
Program: 106161
Project: 106161
Buggy source:
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk,String name,KVMStoragePool destPools);

Fixed version (ground truth):
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk,String name,KVMStoragePool destPools,int timeout);
Program: 106162
Project: 106162
Buggy source:
@Override public KVMPhysicalDisk getPhysicalDisk(String volumeUuid){
  KVMPhysicalDisk disk=null;
  try {
    disk=this._storageAdaptor.getPhysicalDisk(volumeUuid,this);
  }
 catch (  CloudRuntimeException e) {
    if ((this.getStoragePoolType() != StoragePoolType.NetworkFilesystem) || (this.getStoragePoolType() != StoragePoolType.Filesystem)) {
      throw e;
    }
  }
  if (disk != null) {
    return disk;
  }
  s_logger.debug("String_Node_Str");
  String localPoolPath=this.getLocalPath();
  File f=new File(localPoolPath + File.separator + volumeUuid);
  if (!f.exists()) {
    s_logger.debug("String_Node_Str" + volumeUuid + "String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str" + volumeUuid);
  }
  disk=new KVMPhysicalDisk(f.getPath(),volumeUuid,this);
  disk.setFormat(PhysicalDiskFormat.QCOW2);
  disk.setSize(f.length());
  disk.setVirtualSize(f.length());
  return disk;
}

Fixed version (ground truth):
@Override public KVMPhysicalDisk getPhysicalDisk(String volumeUuid){
  KVMPhysicalDisk disk=null;
  try {
    disk=this._storageAdaptor.getPhysicalDisk(volumeUuid,this);
  }
 catch (  CloudRuntimeException e) {
    if ((this.getStoragePoolType() != StoragePoolType.NetworkFilesystem) && (this.getStoragePoolType() != StoragePoolType.Filesystem)) {
      throw e;
    }
  }
  if (disk != null) {
    return disk;
  }
  s_logger.debug("String_Node_Str");
  String localPoolPath=this.getLocalPath();
  File f=new File(localPoolPath + File.separator + volumeUuid);
  if (!f.exists()) {
    s_logger.debug("String_Node_Str" + volumeUuid + "String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str" + volumeUuid);
  }
  disk=new KVMPhysicalDisk(f.getPath(),volumeUuid,this);
  disk.setFormat(PhysicalDiskFormat.QCOW2);
  disk.setSize(f.length());
  disk.setVirtualSize(f.length());
  return disk;
}
Program: 106165
Project: 106165
Buggy source:
@Override public List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId){
  SearchCriteria<VlanVO> sc=ZoneWideNonDedicatedVlanSearch.create();
  sc.setParameters("String_Node_Str","String_Node_Str",zoneId);
  return listBy(sc);
}

Fixed version (ground truth):
@Override public List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId){
  SearchCriteria<VlanVO> sc=ZoneWideNonDedicatedVlanSearch.create();
  sc.setParameters("String_Node_Str",zoneId);
  return listBy(sc);
}
Program: 106168
Project: 106168
Buggy source:
@Override public void prepareStop(VirtualMachineProfile profile){
  UserVmVO vm=_vmDao.findById(profile.getId());
  if (vm.getState() == State.Running)   collectVmDiskStatistics(vm);
}

Fixed version (ground truth):
@Override public void prepareStop(VirtualMachineProfile profile){
  UserVmVO vm=_vmDao.findById(profile.getId());
  if (vm != null && vm.getState() == State.Stopping)   collectVmDiskStatistics(vm);
}
Program: 106169
Project: 106169
Buggy source:
public ChapInfo getChapInfo(VolumeInfo volumeInfo,DataStore dataStore){
  DataStoreDriver dataStoreDriver=dataStore.getDriver();
  if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
    return ((PrimaryDataStoreDriver)dataStoreDriver).getChapInfo(volumeInfo);
  }
  return null;
}

Fixed version (ground truth):
@Override public ChapInfo getChapInfo(VolumeInfo volumeInfo,DataStore dataStore){
  DataStoreDriver dataStoreDriver=dataStore.getDriver();
  if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
    return ((PrimaryDataStoreDriver)dataStoreDriver).getChapInfo(volumeInfo);
  }
  return null;
}
Program: 106170
Project: 106170
Buggy source:
@Override public void execute(){
  CallContext.current().setEventDetails("String_Node_Str" + getId());
  ServiceOffering serviceOffering=_configService.getServiceOffering(serviceOfferingId);
  if (serviceOffering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + serviceOfferingId);
  }
  VirtualMachine result=null;
  try {
    result=_mgr.upgradeSystemVM(this);
  }
 catch (  ResourceUnavailableException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,ex.getMessage());
  }
catch (  ConcurrentOperationException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
catch (  ManagementServerException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
catch (  VirtualMachineMigrationException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
  if (result != null) {
    SystemVmResponse response=_responseGenerator.createSystemVmResponse(result);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void execute(){
  CallContext.current().setEventDetails("String_Node_Str" + getId());
  ServiceOffering serviceOffering=_entityMgr.findById(ServiceOffering.class,serviceOfferingId);
  if (serviceOffering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + serviceOfferingId);
  }
  VirtualMachine result=null;
  try {
    result=_mgr.upgradeSystemVM(this);
  }
 catch (  ResourceUnavailableException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,ex.getMessage());
  }
catch (  ConcurrentOperationException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
catch (  ManagementServerException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
catch (  VirtualMachineMigrationException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
  if (result != null) {
    SystemVmResponse response=_responseGenerator.createSystemVmResponse(result);
    response.setResponseName(getCommandName());
    setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}
Program: 106171
Project: 106171
Buggy source:
@Override public void execute(){
  CallContext.current().setEventDetails("String_Node_Str" + getId());
  ServiceOffering serviceOffering=_configService.getServiceOffering(serviceOfferingId);
  if (serviceOffering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + serviceOfferingId);
  }
  VirtualMachine result=_mgr.upgradeSystemVM(this);
  if (result != null) {
    SystemVmResponse response=_responseGenerator.createSystemVmResponse(result);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void execute(){
  CallContext.current().setEventDetails("String_Node_Str" + getId());
  ServiceOffering serviceOffering=_entityMgr.findById(ServiceOffering.class,serviceOfferingId);
  if (serviceOffering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + serviceOfferingId);
  }
  VirtualMachine result=_mgr.upgradeSystemVM(this);
  if (result != null) {
    SystemVmResponse response=_responseGenerator.createSystemVmResponse(result);
    response.setResponseName(getCommandName());
    setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}
Program: 106172
Project: 106172
Buggy source:
@Override public long getEntityOwnerId(){
  Account caller=CallContext.current().getCallingAccount();
  if (accountName != null && domainId != null) {
    Account account=_accountService.finalizeOwner(caller,accountName,domainId,projectId);
    return account.getId();
  }
 else   if (projectId != null) {
    Project project=_projectService.getProject(projectId);
    if (project != null) {
      if (project.getState() == Project.State.Active) {
        return project.getProjectAccountId();
      }
 else {
        throw new PermissionDeniedException("String_Node_Str" + project.getState() + "String_Node_Str");
      }
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else   if (networkId != null) {
    Network network=_networkService.getNetwork(networkId);
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    NetworkOffering offering=_configService.getNetworkOffering(network.getNetworkOfferingId());
    DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
    if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
      return caller.getAccountId();
    }
    return network.getAccountId();
  }
 else   if (vpcId != null) {
    Vpc vpc=_vpcService.getVpc(getVpcId());
    if (vpc == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    return vpc.getAccountId();
  }
  return caller.getAccountId();
}

Fixed version (ground truth):
@Override public long getEntityOwnerId(){
  Account caller=CallContext.current().getCallingAccount();
  if (accountName != null && domainId != null) {
    Account account=_accountService.finalizeOwner(caller,accountName,domainId,projectId);
    return account.getId();
  }
 else   if (projectId != null) {
    Project project=_projectService.getProject(projectId);
    if (project != null) {
      if (project.getState() == Project.State.Active) {
        return project.getProjectAccountId();
      }
 else {
        throw new PermissionDeniedException("String_Node_Str" + project.getState() + "String_Node_Str");
      }
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else   if (networkId != null) {
    Network network=_networkService.getNetwork(networkId);
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    NetworkOffering offering=_entityMgr.findById(NetworkOffering.class,network.getNetworkOfferingId());
    DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
    if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
      return caller.getAccountId();
    }
    return network.getAccountId();
  }
 else   if (vpcId != null) {
    Vpc vpc=_vpcService.getVpc(getVpcId());
    if (vpc == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    return vpc.getAccountId();
  }
  return caller.getAccountId();
}
Program: 106173
Project: 106173
Buggy source:
@Override public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
  CallContext.current().setEventDetails("String_Node_Str" + getEntityId());
  IpAddress result=null;
  if (getVpcId() != null) {
    result=_vpcService.associateIPToVpc(getEntityId(),getVpcId());
  }
 else   if (getNetworkId() != null) {
    result=_networkService.associateIPToNetwork(getEntityId(),getNetworkId());
  }
  if (result != null) {
    IPAddressResponse ipResponse=_responseGenerator.createIPAddressResponse(result);
    ipResponse.setResponseName(getCommandName());
    this.setResponseObject(ipResponse);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
  CallContext.current().setEventDetails("String_Node_Str" + getEntityId());
  IpAddress result=null;
  if (getVpcId() != null) {
    result=_vpcService.associateIPToVpc(getEntityId(),getVpcId());
  }
 else   if (getNetworkId() != null) {
    result=_networkService.associateIPToNetwork(getEntityId(),getNetworkId());
  }
  if (result != null) {
    IPAddressResponse ipResponse=_responseGenerator.createIPAddressResponse(result);
    ipResponse.setResponseName(getCommandName());
    setResponseObject(ipResponse);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}
Program: 106174
Project: 106174
Buggy source:
@Override public void create() throws ResourceAllocationException {
  try {
    IpAddress ip=null;
    if (!isPortable()) {
      ip=_networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()),getZoneId(),getNetworkId());
    }
 else {
      ip=_networkService.allocatePortableIP(_accountService.getAccount(getEntityOwnerId()),1,getZoneId(),getNetworkId(),getVpcId());
    }
    if (ip != null) {
      this.setEntityId(ip.getId());
      this.setEntityUuid(ip.getUuid());
    }
 else {
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
    }
  }
 catch (  ConcurrentOperationException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
catch (  InsufficientAddressCapacityException ex) {
    s_logger.info(ex);
    s_logger.trace(ex);
    throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR,ex.getMessage());
  }
}

Fixed version (ground truth):
@Override public void create() throws ResourceAllocationException {
  try {
    IpAddress ip=null;
    if (!isPortable()) {
      ip=_networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()),getZoneId(),getNetworkId());
    }
 else {
      ip=_networkService.allocatePortableIP(_accountService.getAccount(getEntityOwnerId()),1,getZoneId(),getNetworkId(),getVpcId());
    }
    if (ip != null) {
      setEntityId(ip.getId());
      setEntityUuid(ip.getUuid());
    }
 else {
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
    }
  }
 catch (  ConcurrentOperationException ex) {
    s_logger.warn("String_Node_Str",ex);
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
  }
catch (  InsufficientAddressCapacityException ex) {
    s_logger.info(ex);
    s_logger.trace(ex);
    throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR,ex.getMessage());
  }
}
Program: 106175
Project: 106175
Buggy source:
public Long getPhysicalNetworkId(){
  NetworkOffering offering=_configService.getNetworkOffering(networkOfferingId);
  if (offering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + networkOfferingId);
  }
  if (physicalNetworkId != null) {
    if (offering.getGuestType() == GuestType.Shared) {
      return physicalNetworkId;
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str" + GuestType.Shared + "String_Node_Str");
    }
  }
 else {
    if (zoneId == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    return _networkService.findPhysicalNetworkId(zoneId,offering.getTags(),offering.getTrafficType());
  }
}

Fixed version (ground truth):
public Long getPhysicalNetworkId(){
  NetworkOffering offering=_entityMgr.findById(NetworkOffering.class,networkOfferingId);
  if (offering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + networkOfferingId);
  }
  if (physicalNetworkId != null) {
    if (offering.getGuestType() == GuestType.Shared) {
      return physicalNetworkId;
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str" + GuestType.Shared + "String_Node_Str");
    }
  }
 else {
    if (zoneId == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    return _networkService.findPhysicalNetworkId(zoneId,offering.getTags(),offering.getTrafficType());
  }
}
Program: 106176
Project: 106176
Buggy source:
@Override public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
  Network result=_networkService.createGuestNetwork(this);
  if (result != null) {
    NetworkResponse response=_responseGenerator.createNetworkResponse(result);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
  Network result=_networkService.createGuestNetwork(this);
  if (result != null) {
    NetworkResponse response=_responseGenerator.createNetworkResponse(result);
    response.setResponseName(getCommandName());
    setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}
Program: 106178
Project: 106178
Buggy source:
@Override public void execute(){
  UserVm result;
  if (getStartVm()) {
    try {
      CallContext.current().setEventDetails("String_Node_Str" + getEntityId());
      result=_userVmService.startVirtualMachine(this);
    }
 catch (    ResourceUnavailableException ex) {
      s_logger.warn("String_Node_Str",ex);
      throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,ex.getMessage());
    }
catch (    ConcurrentOperationException ex) {
      s_logger.warn("String_Node_Str",ex);
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
    }
catch (    InsufficientCapacityException ex) {
      StringBuilder message=new StringBuilder(ex.getMessage());
      if (ex instanceof InsufficientServerCapacityException) {
        if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
          message.append("String_Node_Str");
        }
      }
      s_logger.info(ex);
      s_logger.info(message.toString(),ex);
      throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR,message.toString());
    }
  }
 else {
    result=_userVmService.getUserVm(getEntityId());
  }
  if (result != null) {
    UserVmResponse response=_responseGenerator.createUserVmResponse("String_Node_Str",result).get(0);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void execute(){
  UserVm result;
  if (getStartVm()) {
    try {
      CallContext.current().setEventDetails("String_Node_Str" + getEntityId());
      result=_userVmService.startVirtualMachine(this);
    }
 catch (    ResourceUnavailableException ex) {
      s_logger.warn("String_Node_Str",ex);
      throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,ex.getMessage());
    }
catch (    ConcurrentOperationException ex) {
      s_logger.warn("String_Node_Str",ex);
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,ex.getMessage());
    }
catch (    InsufficientCapacityException ex) {
      StringBuilder message=new StringBuilder(ex.getMessage());
      if (ex instanceof InsufficientServerCapacityException) {
        if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
          message.append("String_Node_Str");
        }
      }
      s_logger.info(ex);
      s_logger.info(message.toString(),ex);
      throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR,message.toString());
    }
  }
 else {
    result=_userVmService.getUserVm(getEntityId());
  }
  if (result != null) {
    UserVmResponse response=_responseGenerator.createUserVmResponse("String_Node_Str",result).get(0);
    response.setResponseName(getCommandName());
    setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}
Program: 106179
Project: 106179
Buggy source:
@Override public void execute() throws ResourceAllocationException {
  CallContext.current().setEventDetails("String_Node_Str" + getId());
  ServiceOffering serviceOffering=_configService.getServiceOffering(serviceOfferingId);
  if (serviceOffering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + serviceOfferingId);
  }
  UserVm result=_userVmService.upgradeVirtualMachine(this);
  if (result != null) {
    UserVmResponse response=_responseGenerator.createUserVmResponse("String_Node_Str",result).get(0);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void execute() throws ResourceAllocationException {
  CallContext.current().setEventDetails("String_Node_Str" + getId());
  ServiceOffering serviceOffering=_entityMgr.findById(ServiceOffering.class,serviceOfferingId);
  if (serviceOffering == null) {
    throw new InvalidParameterValueException("String_Node_Str" + serviceOfferingId);
  }
  UserVm result=_userVmService.upgradeVirtualMachine(this);
  if (result != null) {
    UserVmResponse response=_responseGenerator.createUserVmResponse("String_Node_Str",result).get(0);
    response.setResponseName(getCommandName());
    setResponseObject(response);
  }
 else {
    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"String_Node_Str");
  }
}
Program: 106181
Project: 106181
Buggy source:
@Override public boolean upgradeVmDb(long vmId,long serviceOfferingId){
  VMInstanceVO vmForUpdate=_vmDao.createForUpdate();
  vmForUpdate.setServiceOfferingId(serviceOfferingId);
  ServiceOffering newSvcOff=_configMgr.getServiceOffering(serviceOfferingId);
  vmForUpdate.setHaEnabled(newSvcOff.getOfferHA());
  vmForUpdate.setLimitCpuUse(newSvcOff.getLimitCpuUse());
  vmForUpdate.setServiceOfferingId(newSvcOff.getId());
  return _vmDao.update(vmId,vmForUpdate);
}

Fixed version (ground truth):
@Override public boolean upgradeVmDb(long vmId,long serviceOfferingId){
  VMInstanceVO vmForUpdate=_vmDao.createForUpdate();
  vmForUpdate.setServiceOfferingId(serviceOfferingId);
  ServiceOffering newSvcOff=_entityMgr.findById(ServiceOffering.class,serviceOfferingId);
  vmForUpdate.setHaEnabled(newSvcOff.getOfferHA());
  vmForUpdate.setLimitCpuUse(newSvcOff.getLimitCpuUse());
  vmForUpdate.setServiceOfferingId(newSvcOff.getId());
  return _vmDao.update(vmId,vmForUpdate);
}
Program: 106183
Project: 106183
Buggy source:
@Before public void setup() throws IOException {
  pidFile=File.createTempFile("String_Node_Str","String_Node_Str",new File("String_Node_Str"));
}

Fixed version (ground truth):
@Before public void setup() throws IOException {
  pidFile=File.createTempFile("String_Node_Str","String_Node_Str");
}
Program: 106185
Project: 106185
Buggy source:
@Override public String toString(){
  if (toString == null) {
    toString=new StringBuilder("String_Node_Str").append(id).append("String_Node_Str").append(hostName).append("String_Node_Str").toString();
  }
  return toString;
}

Fixed version (ground truth):
@Override public String toString(){
  if (toString == null) {
    toString=new StringBuilder("String_Node_Str").append(id).append("String_Node_Str").append(name).append("String_Node_Str").toString();
  }
  return toString;
}
Program: 106186
Project: 106186
Buggy source:
/** 
 * Give hypervisor guru opportunity to decide if certain command needs to be delegated to other host, mainly to secondary storage VM host
 * @param hostId original hypervisor host
 * @param cmd command that is going to be sent, hypervisor guru usually needs to register various context objects into the command object
 * @return delegated host id if the command will be delegated
 */
long getCommandHostDelegation(long hostId,Command cmd);

Fixed version (ground truth):
/** 
 * Give hypervisor guru opportunity to decide if certain command needs to be delegated to other host, mainly to secondary storage VM host
 * @param hostId original hypervisor host
 * @param cmd command that is going to be sent, hypervisor guru usually needs to register various context objects into the command object
 * @return delegated host id if the command will be delegated
 */
Pair<Boolean,Long> getCommandHostDelegation(long hostId,Command cmd);
Program: 106187
Project: 106187
Buggy source:
public HypervisorType getHypervisorType(){
  return hypervisorType;
}

Fixed version (ground truth):
@Override public HypervisorType getHypervisorType(){
  return hypervisorType;
}
Program: 106188
Project: 106188
Buggy source:
public TemplateObjectTO(TemplateInfo template){
  this.path=template.getInstallPath();
  this.uuid=template.getUuid();
  this.id=template.getId();
  this.origUrl=template.getUrl();
  this.displayText=template.getDisplayText();
  this.checksum=template.getChecksum();
  this.hvm=template.isRequiresHvm();
  this.accountId=template.getAccountId();
  this.name=template.getUniqueName();
  this.format=template.getFormat();
  if (template.getDataStore() != null) {
    this.imageDataStore=template.getDataStore().getTO();
  }
}

Fixed version (ground truth):
public TemplateObjectTO(TemplateInfo template){
  this.path=template.getInstallPath();
  this.uuid=template.getUuid();
  this.id=template.getId();
  this.origUrl=template.getUrl();
  this.displayText=template.getDisplayText();
  this.checksum=template.getChecksum();
  this.hvm=template.isRequiresHvm();
  this.accountId=template.getAccountId();
  this.name=template.getUniqueName();
  this.format=template.getFormat();
  if (template.getDataStore() != null) {
    this.imageDataStore=template.getDataStore().getTO();
  }
  this.hypervisorType=template.getHypervisorType();
}
Program: 106189
Project: 106189
Buggy source:
public VolumeObjectTO(VolumeInfo volume){
  this.uuid=volume.getUuid();
  this.path=volume.getPath();
  this.accountId=volume.getAccountId();
  if (volume.getDataStore() != null) {
    this.dataStore=volume.getDataStore().getTO();
  }
 else {
    this.dataStore=null;
  }
  this.vmName=volume.getAttachedVmName();
  this.size=volume.getSize();
  this.setVolumeId(volume.getId());
  this.chainInfo=volume.getChainInfo();
  this.volumeType=volume.getVolumeType();
  this.name=volume.getName();
  this.setId(volume.getId());
  this.format=volume.getFormat();
  this.bytesReadRate=volume.getBytesReadRate();
  this.bytesWriteRate=volume.getBytesWriteRate();
  this.iopsReadRate=volume.getIopsReadRate();
  this.iopsWriteRate=volume.getIopsWriteRate();
}

Fixed version (ground truth):
public VolumeObjectTO(VolumeInfo volume){
  this.uuid=volume.getUuid();
  this.path=volume.getPath();
  this.accountId=volume.getAccountId();
  if (volume.getDataStore() != null) {
    this.dataStore=volume.getDataStore().getTO();
  }
 else {
    this.dataStore=null;
  }
  this.vmName=volume.getAttachedVmName();
  this.size=volume.getSize();
  this.setVolumeId(volume.getId());
  this.chainInfo=volume.getChainInfo();
  this.volumeType=volume.getVolumeType();
  this.name=volume.getName();
  this.setId(volume.getId());
  this.format=volume.getFormat();
  this.bytesReadRate=volume.getBytesReadRate();
  this.bytesWriteRate=volume.getBytesWriteRate();
  this.iopsReadRate=volume.getIopsReadRate();
  this.iopsWriteRate=volume.getIopsWriteRate();
  this.hypervisorType=volume.getHypervisorType();
}
Program: 106191
Project: 106191
Buggy source:
public Boolean getDisplayVolume(){
  return displayVolume != null ? displayVolume : Boolean.TRUE;
}

Fixed version (ground truth):
public Boolean getDisplayVolume(){
  return displayVolume;
}
Program: 106192
Project: 106192
Buggy source:
public AsyncJob.Type getInstanceType(){
  return AsyncJob.Type.Volume;
}

Fixed version (ground truth):
@Override public AsyncJob.Type getInstanceType(){
  return AsyncJob.Type.Volume;
}
Program: 106194
Project: 106194
Buggy source:
@Override public S3TO toS3TO(){
  Boolean httpsFlag=null;
  if (this.httpsFlag != null) {
    httpsFlag=this.httpsFlag == 0 ? false : true;
  }
  return new S3TO(this.id,this.uuid,this.accessKey,this.secretKey,this.endPoint,this.bucketName,httpsFlag,this.connectionTimeout,this.maxErrorRetry,this.socketTimeout,this.created);
}

Fixed version (ground truth):
@Override public S3TO toS3TO(){
  Boolean httpsFlag=null;
  if (this.httpsFlag != null) {
    httpsFlag=this.httpsFlag == 0 ? false : true;
  }
  return new S3TO(this.id,this.uuid,this.accessKey,this.secretKey,this.endPoint,this.bucketName,httpsFlag,this.connectionTimeout,this.maxErrorRetry,this.socketTimeout,this.created,false);
}
Program: 106197
Project: 106197
Buggy source:
Map<String,TemplateProp> s3ListTemplate(S3TO s3){
  String bucket=s3.getBucketName();
  final List<S3ObjectSummary> objectSummaries=S3Utils.getDirectory(s3,bucket,this.TEMPLATE_ROOT_DIR);
  if (objectSummaries == null)   return null;
  Map<String,TemplateProp> tmpltInfos=new HashMap<String,TemplateProp>();
  for (  S3ObjectSummary objectSummary : objectSummaries) {
    String key=objectSummary.getKey();
    String installPath=StringUtils.substringBeforeLast(key,S3Utils.SEPARATOR);
    String uniqueName=this.determineS3TemplateNameFromKey(key);
    TemplateProp tInfo=new TemplateProp(uniqueName,installPath,objectSummary.getSize(),objectSummary.getSize(),true,false);
    tmpltInfos.put(uniqueName,tInfo);
  }
  return tmpltInfos;
}

Fixed version (ground truth):
Map<String,TemplateProp> s3ListTemplate(S3TO s3){
  String bucket=s3.getBucketName();
  final List<S3ObjectSummary> objectSummaries=S3Utils.getDirectory(s3,bucket,this.TEMPLATE_ROOT_DIR);
  if (objectSummaries == null)   return null;
  Map<String,TemplateProp> tmpltInfos=new HashMap<String,TemplateProp>();
  for (  S3ObjectSummary objectSummary : objectSummaries) {
    String key=objectSummary.getKey();
    String uniqueName=this.determineS3TemplateNameFromKey(key);
    TemplateProp tInfo=new TemplateProp(uniqueName,key,objectSummary.getSize(),objectSummary.getSize(),true,false);
    tmpltInfos.put(uniqueName,tInfo);
  }
  return tmpltInfos;
}
Program: 106198
Project: 106198
Buggy source:
Map<Long,TemplateProp> s3ListVolume(S3TO s3){
  String bucket=s3.getBucketName();
  final List<S3ObjectSummary> objectSummaries=S3Utils.getDirectory(s3,bucket,this.VOLUME_ROOT_DIR);
  if (objectSummaries == null)   return null;
  Map<Long,TemplateProp> tmpltInfos=new HashMap<Long,TemplateProp>();
  for (  S3ObjectSummary objectSummary : objectSummaries) {
    String key=objectSummary.getKey();
    String installPath=StringUtils.substringBeforeLast(key,S3Utils.SEPARATOR);
    Long id=this.determineS3VolumeIdFromKey(key);
    TemplateProp tInfo=new TemplateProp(id.toString(),installPath,objectSummary.getSize(),objectSummary.getSize(),true,false);
    tmpltInfos.put(id,tInfo);
  }
  return tmpltInfos;
}

Fixed version (ground truth):
Map<Long,TemplateProp> s3ListVolume(S3TO s3){
  String bucket=s3.getBucketName();
  final List<S3ObjectSummary> objectSummaries=S3Utils.getDirectory(s3,bucket,this.VOLUME_ROOT_DIR);
  if (objectSummaries == null)   return null;
  Map<Long,TemplateProp> tmpltInfos=new HashMap<Long,TemplateProp>();
  for (  S3ObjectSummary objectSummary : objectSummaries) {
    String key=objectSummary.getKey();
    Long id=this.determineS3VolumeIdFromKey(key);
    TemplateProp tInfo=new TemplateProp(id.toString(),key,objectSummary.getSize(),objectSummary.getSize(),true,false);
    tmpltInfos.put(id,tInfo);
  }
  return tmpltInfos;
}
Program: 106199
Project: 106199
Buggy source:
@Override public void prepareStop(VirtualMachineProfile<UserVmVO> profile){
  UserVmVO vm=profile.getVirtualMachine();
  if (vm.getState() == State.Running)   collectVmDiskStatistics(vm);
}

Fixed version (ground truth):
@Override public void prepareStop(VirtualMachineProfile<UserVmVO> profile){
  UserVmVO vm=_vmDao.findById(profile.getId());
  if (vm.getState() == State.Running)   collectVmDiskStatistics(vm);
}
Program: 106200
Project: 106200
Buggy source:
public boolean stateTransit(Volume.Event event){
  boolean result=false;
  try {
    volumeVO=volumeDao.findById(volumeVO.getId());
    result=_volStateMachine.transitTo(volumeVO,event,null,volumeDao);
    volumeVO=volumeDao.findById(volumeVO.getId());
  }
 catch (  NoTransitionException e) {
    String errorMessage="String_Node_Str" + this.getVolumeId() + "String_Node_Str"+ e.toString();
    s_logger.debug(errorMessage);
    throw new CloudRuntimeException(errorMessage);
  }
  return result;
}

Fixed version (ground truth):
@Override public boolean stateTransit(Volume.Event event){
  boolean result=false;
  try {
    volumeVO=volumeDao.findById(volumeVO.getId());
    result=_volStateMachine.transitTo(volumeVO,event,null,volumeDao);
    volumeVO=volumeDao.findById(volumeVO.getId());
  }
 catch (  NoTransitionException e) {
    String errorMessage="String_Node_Str" + this.getVolumeId() + "String_Node_Str"+ e.toString();
    s_logger.debug(errorMessage);
    throw new CloudRuntimeException(errorMessage);
  }
  return result;
}
Program: 106201
Project: 106201
Buggy source:
protected Void copyVolumeFromImageToPrimaryCallback(AsyncCallbackDispatcher<VolumeServiceImpl,CopyCommandResult> callback,CopyVolumeContext<VolumeApiResult> context){
  VolumeInfo srcVolume=context.srcVolume;
  VolumeInfo destVolume=context.destVolume;
  CopyCommandResult result=callback.getResult();
  AsyncCallFuture<VolumeApiResult> future=context.future;
  VolumeApiResult res=new VolumeApiResult(destVolume);
  try {
    if (res.isFailed()) {
      destVolume.processEvent(Event.OperationFailed);
      srcVolume.processEvent(Event.OperationFailed);
      res.setResult(result.getResult());
      future.complete(res);
    }
    srcVolume.processEvent(Event.OperationSuccessed);
    destVolume.processEvent(Event.OperationSuccessed,result.getAnswer());
    srcVolume.getDataStore().delete(srcVolume);
    future.complete(res);
  }
 catch (  Exception e) {
    res.setResult(e.toString());
    future.complete(res);
  }
  return null;
}

Fixed version (ground truth):
protected Void copyVolumeFromImageToPrimaryCallback(AsyncCallbackDispatcher<VolumeServiceImpl,CopyCommandResult> callback,CopyVolumeContext<VolumeApiResult> context){
  VolumeInfo srcVolume=context.srcVolume;
  VolumeInfo destVolume=context.destVolume;
  CopyCommandResult result=callback.getResult();
  AsyncCallFuture<VolumeApiResult> future=context.future;
  VolumeApiResult res=new VolumeApiResult(destVolume);
  try {
    if (res.isFailed()) {
      destVolume.processEvent(Event.OperationFailed);
      srcVolume.processEvent(Event.OperationFailed);
      res.setResult(result.getResult());
      future.complete(res);
      return null;
    }
    srcVolume.processEvent(Event.OperationSuccessed);
    destVolume.processEvent(Event.OperationSuccessed,result.getAnswer());
    srcVolume.getDataStore().delete(srcVolume);
    future.complete(res);
  }
 catch (  Exception e) {
    res.setResult(e.toString());
    future.complete(res);
  }
  return null;
}
Program: 106202
Project: 106202
Buggy source:
protected Void copyVolumeFromPrimaryToImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl,CopyCommandResult> callback,CopyVolumeContext<VolumeApiResult> context){
  VolumeInfo srcVolume=context.srcVolume;
  VolumeInfo destVolume=context.destVolume;
  CopyCommandResult result=callback.getResult();
  AsyncCallFuture<VolumeApiResult> future=context.future;
  VolumeApiResult res=new VolumeApiResult(destVolume);
  try {
    if (res.isFailed()) {
      destVolume.processEvent(Event.OperationFailed);
      srcVolume.processEvent(Event.OperationFailed);
      res.setResult(result.getResult());
      future.complete(res);
    }
 else {
      srcVolume.processEvent(Event.OperationSuccessed);
      destVolume.processEvent(Event.OperationSuccessed,result.getAnswer());
      future.complete(res);
    }
  }
 catch (  Exception e) {
    res.setResult(e.toString());
    future.complete(res);
  }
  return null;
}

Fixed version (ground truth):
protected Void copyVolumeFromPrimaryToImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl,CopyCommandResult> callback,CopyVolumeContext<VolumeApiResult> context){
  VolumeInfo srcVolume=context.srcVolume;
  VolumeInfo destVolume=context.destVolume;
  CopyCommandResult result=callback.getResult();
  AsyncCallFuture<VolumeApiResult> future=context.future;
  VolumeApiResult res=new VolumeApiResult(destVolume);
  try {
    if (res.isFailed()) {
      srcVolume.processEvent(Event.OperationFailed);
      destVolume.processEventOnly(Event.OperationFailed);
      res.setResult(result.getResult());
      future.complete(res);
    }
 else {
      srcVolume.processEvent(Event.OperationSuccessed);
      destVolume.processEventOnly(Event.OperationSuccessed,result.getAnswer());
      future.complete(res);
    }
  }
 catch (  Exception e) {
    res.setResult(e.toString());
    future.complete(res);
  }
  return null;
}
Program: 106203
Project: 106203
Buggy source:
protected AsyncCallFuture<VolumeApiResult> copyVolumeFromPrimaryToImage(VolumeInfo srcVolume,DataStore destStore){
  AsyncCallFuture<VolumeApiResult> future=new AsyncCallFuture<VolumeApiResult>();
  VolumeApiResult res=new VolumeApiResult(srcVolume);
  VolumeInfo destVolume=null;
  try {
    destVolume=(VolumeInfo)destStore.create(srcVolume);
    destVolume.processEvent(Event.CreateOnlyRequested);
    srcVolume.processEvent(Event.CopyingRequested);
    CopyVolumeContext<VolumeApiResult> context=new CopyVolumeContext<VolumeApiResult>(null,future,srcVolume,destVolume,destStore);
    AsyncCallbackDispatcher<VolumeServiceImpl,CopyCommandResult> caller=AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null,null)).setContext(context);
    motionSrv.copyAsync(srcVolume,destVolume,caller);
    return future;
  }
 catch (  Exception e) {
    s_logger.error("String_Node_Str",e);
    if (destVolume != null) {
      destVolume.processEvent(Event.OperationFailed);
    }
    srcVolume.processEvent(Event.OperationFailed);
    res.setResult(e.toString());
    future.complete(res);
    return future;
  }
}

Fixed version (ground truth):
protected AsyncCallFuture<VolumeApiResult> copyVolumeFromPrimaryToImage(VolumeInfo srcVolume,DataStore destStore){
  AsyncCallFuture<VolumeApiResult> future=new AsyncCallFuture<VolumeApiResult>();
  VolumeApiResult res=new VolumeApiResult(srcVolume);
  VolumeInfo destVolume=null;
  try {
    destVolume=(VolumeInfo)destStore.create(srcVolume);
    srcVolume.processEvent(Event.MigrationRequested);
    destVolume.processEventOnly(Event.CreateOnlyRequested);
    CopyVolumeContext<VolumeApiResult> context=new CopyVolumeContext<VolumeApiResult>(null,future,srcVolume,destVolume,destStore);
    AsyncCallbackDispatcher<VolumeServiceImpl,CopyCommandResult> caller=AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null,null)).setContext(context);
    motionSrv.copyAsync(srcVolume,destVolume,caller);
    return future;
  }
 catch (  Exception e) {
    s_logger.error("String_Node_Str",e);
    if (destVolume != null) {
      destVolume.getDataStore().delete(destVolume);
    }
    srcVolume.processEvent(Event.OperationFailed);
    res.setResult(e.toString());
    future.complete(res);
    return future;
  }
}