Program: 106334
Project: 106334
Buggy source:
private Pair<String,String> copyVolumeToSecStorage(VmwareHostService hostService,VmwareHypervisorHost hyperHost,CopyVolumeCommand cmd,String vmName,long volumeId,String poolId,String volumePath,String secStorageUrl,String workerVmName) throws Exception {
  String volumeFolder=String.valueOf(volumeId) + "String_Node_Str";
  VirtualMachineMO workerVm=null;
  VirtualMachineMO vmMo=null;
  String exportName=UUID.randomUUID().toString();
  try {
    ManagedObjectReference morDs=HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,poolId);
    if (morDs == null) {
      String msg="String_Node_Str";
      s_logger.error(msg);
      throw new Exception(msg);
    }
    vmMo=hyperHost.findVmOnHyperHost(vmName);
    if (vmMo == null) {
      DatastoreMO dsMo=new DatastoreMO(hyperHost.getContext(),morDs);
      VirtualMachineConfigSpec vmConfig=new VirtualMachineConfigSpec();
      vmConfig.setName(workerVmName);
      vmConfig.setMemoryMB((long)4);
      vmConfig.setNumCPUs(1);
      vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.toString());
      VirtualMachineFileInfo fileInfo=new VirtualMachineFileInfo();
      fileInfo.setVmPathName(String.format("String_Node_Str",dsMo.getName()));
      vmConfig.setFiles(fileInfo);
      VirtualLsiLogicController scsiController=new VirtualLsiLogicController();
      scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
      scsiController.setBusNumber(0);
      scsiController.setKey(1);
      VirtualDeviceConfigSpec scsiControllerSpec=new VirtualDeviceConfigSpec();
      scsiControllerSpec.setDevice(scsiController);
      scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
      vmConfig.getDeviceChange().add(scsiControllerSpec);
      hyperHost.createVm(vmConfig);
      workerVm=hyperHost.findVmOnHyperHost(workerVmName);
      if (workerVm == null) {
        String msg="String_Node_Str";
        s_logger.error(msg);
        throw new Exception(msg);
      }
      String datastoreVolumePath=String.format("String_Node_Str",dsMo.getName(),volumePath);
      workerVm.attachDisk(new String[]{datastoreVolumePath},morDs);
      vmMo=workerVm;
    }
    vmMo.createSnapshot(exportName,"String_Node_Str",false,false);
    exportVolumeToSecondaryStroage(vmMo,volumePath,secStorageUrl,"String_Node_Str" + volumeFolder,exportName,hostService.getWorkerName(hyperHost.getContext(),cmd,1));
    return new Pair<String,String>(volumeFolder,exportName);
  }
  finally {
    vmMo.removeSnapshot(exportName,false);
    if (workerVm != null) {
      workerVm.detachAllDisks();
      workerVm.destroy();
    }
  }
}

Fixed version (ground truth):
private Pair<String,String> copyVolumeToSecStorage(VmwareHostService hostService,VmwareHypervisorHost hyperHost,CopyVolumeCommand cmd,String vmName,long volumeId,String poolId,String volumePath,String secStorageUrl,String workerVmName) throws Exception {
  String volumeFolder=String.valueOf(volumeId) + "String_Node_Str";
  VirtualMachineMO workerVm=null;
  VirtualMachineMO vmMo=null;
  String exportName=UUID.randomUUID().toString();
  try {
    ManagedObjectReference morDs=HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,poolId);
    if (morDs == null) {
      String msg="String_Node_Str";
      s_logger.error(msg);
      throw new Exception(msg);
    }
    vmMo=hyperHost.findVmOnHyperHost(vmName);
    if (vmMo == null) {
      DatastoreMO dsMo=new DatastoreMO(hyperHost.getContext(),morDs);
      VirtualMachineConfigSpec vmConfig=new VirtualMachineConfigSpec();
      vmConfig.setName(workerVmName);
      vmConfig.setMemoryMB((long)4);
      vmConfig.setNumCPUs(1);
      vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
      VirtualMachineFileInfo fileInfo=new VirtualMachineFileInfo();
      fileInfo.setVmPathName(String.format("String_Node_Str",dsMo.getName()));
      vmConfig.setFiles(fileInfo);
      VirtualLsiLogicController scsiController=new VirtualLsiLogicController();
      scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
      scsiController.setBusNumber(0);
      scsiController.setKey(1);
      VirtualDeviceConfigSpec scsiControllerSpec=new VirtualDeviceConfigSpec();
      scsiControllerSpec.setDevice(scsiController);
      scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
      vmConfig.getDeviceChange().add(scsiControllerSpec);
      hyperHost.createVm(vmConfig);
      workerVm=hyperHost.findVmOnHyperHost(workerVmName);
      if (workerVm == null) {
        String msg="String_Node_Str";
        s_logger.error(msg);
        throw new Exception(msg);
      }
      String datastoreVolumePath=String.format("String_Node_Str",dsMo.getName(),volumePath);
      workerVm.attachDisk(new String[]{datastoreVolumePath},morDs);
      vmMo=workerVm;
    }
    vmMo.createSnapshot(exportName,"String_Node_Str",false,false);
    exportVolumeToSecondaryStroage(vmMo,volumePath,secStorageUrl,"String_Node_Str" + volumeFolder,exportName,hostService.getWorkerName(hyperHost.getContext(),cmd,1));
    return new Pair<String,String>(volumeFolder,exportName);
  }
  finally {
    vmMo.removeSnapshot(exportName,false);
    if (workerVm != null) {
      workerVm.detachAllDisks();
      workerVm.destroy();
    }
  }
}