Program: 105312
Project: 105312
Buggy source:
public void exportVm(String exportDir,String exportName,boolean packToOva,boolean leaveOvaFileOnly) throws Exception {
  ManagedObjectReference morOvf=_context.getServiceContent().getOvfManager();
  VirtualMachineRuntimeInfo runtimeInfo=getRuntimeInfo();
  HostMO hostMo=new HostMO(_context,runtimeInfo.getHost());
  String hostName=hostMo.getHostName();
  String vmName=getVmName();
  DatacenterMO dcMo=new DatacenterMO(_context,hostMo.getHyperHostDatacenter());
  if (runtimeInfo.getPowerState() != VirtualMachinePowerState.POWERED_OFF) {
    String msg="String_Node_Str" + vmName + "String_Node_Str"+ hostName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  ManagedObjectReference morLease=_context.getService().exportVm(getMor());
  if (morLease == null) {
    s_logger.error("String_Node_Str");
    throw new Exception("String_Node_Str");
  }
  HttpNfcLeaseMO leaseMo=new HttpNfcLeaseMO(_context,morLease);
  HttpNfcLeaseState state=leaseMo.waitState(new HttpNfcLeaseState[]{HttpNfcLeaseState.READY,HttpNfcLeaseState.ERROR});
  try {
    if (state == HttpNfcLeaseState.READY) {
      final HttpNfcLeaseMO.ProgressReporter progressReporter=leaseMo.createProgressReporter();
      boolean success=false;
      List<String> fileNames=new ArrayList<String>();
      try {
        HttpNfcLeaseInfo leaseInfo=leaseMo.getLeaseInfo();
        final long totalBytes=leaseInfo.getTotalDiskCapacityInKB() * 1024;
        long totalBytesDownloaded=0;
        List<HttpNfcLeaseDeviceUrl> deviceUrls=leaseInfo.getDeviceUrl();
        s_logger.info("String_Node_Str" + System.currentTimeMillis());
        if (deviceUrls != null) {
          OvfFile[] ovfFiles=new OvfFile[deviceUrls.size()];
          for (int i=0; i < deviceUrls.size(); i++) {
            String deviceId=deviceUrls.get(i).getKey();
            String deviceUrlStr=deviceUrls.get(i).getUrl();
            String orgDiskFileName=deviceUrlStr.substring(deviceUrlStr.lastIndexOf("String_Node_Str") + 1);
            String diskFileName=String.format("String_Node_Str",exportName,i,VmwareHelper.getFileExtension(orgDiskFileName,"String_Node_Str"));
            String diskUrlStr=deviceUrlStr.replace("String_Node_Str",hostName);
            diskUrlStr=HypervisorHostHelper.resolveHostNameInUrl(dcMo,diskUrlStr);
            String diskLocalPath=exportDir + File.separator + diskFileName;
            fileNames.add(diskLocalPath);
            if (s_logger.isInfoEnabled()) {
              s_logger.info("String_Node_Str" + deviceUrlStr);
            }
            long lengthOfDiskFile=_context.downloadVmdkFile(diskUrlStr,diskLocalPath,totalBytesDownloaded,new ActionDelegate<Long>(){
              @Override public void action(              Long param){
                if (s_logger.isTraceEnabled()) {
                  s_logger.trace("String_Node_Str" + param + "String_Node_Str"+ totalBytes);
                }
                progressReporter.reportProgress((int)(param * 100 / totalBytes));
              }
            }
);
            totalBytesDownloaded+=lengthOfDiskFile;
            OvfFile ovfFile=new OvfFile();
            ovfFile.setPath(diskFileName);
            ovfFile.setDeviceId(deviceId);
            ovfFile.setSize(lengthOfDiskFile);
            ovfFiles[i]=ovfFile;
          }
          OvfCreateDescriptorParams ovfDescParams=new OvfCreateDescriptorParams();
          ovfDescParams.getOvfFiles().addAll(Arrays.asList(ovfFiles));
          OvfCreateDescriptorResult ovfCreateDescriptorResult=_context.getService().createDescriptor(morOvf,getMor(),ovfDescParams);
          String ovfPath=exportDir + File.separator + exportName+ "String_Node_Str";
          fileNames.add(ovfPath);
          FileWriter out=new FileWriter(ovfPath);
          out.write(ovfCreateDescriptorResult.getOvfDescriptor());
          out.close();
          if (packToOva) {
            s_logger.info("String_Node_Str");
            Script commandSync=new Script(true,"String_Node_Str",0,s_logger);
            commandSync.execute();
            Script command=new Script(false,"String_Node_Str",0,s_logger);
            command.setWorkDir(exportDir);
            command.add("String_Node_Str",exportName + "String_Node_Str");
            command.add(exportName + "String_Node_Str");
            for (            String name : fileNames) {
              command.add((new File(name).getName()));
            }
            s_logger.info("String_Node_Str" + command.toString());
            command.execute();
            if ((new File(exportDir + File.separator + exportName+ "String_Node_Str")).exists()) {
              success=true;
            }
 else {
              s_logger.error(exportDir + File.separator + exportName+ "String_Node_Str");
            }
          }
 else {
            success=true;
          }
        }
        s_logger.info("String_Node_Str" + System.currentTimeMillis());
      }
 catch (      Throwable e) {
        s_logger.error("String_Node_Str",e);
      }
 finally {
        progressReporter.close();
        if (leaveOvaFileOnly) {
          for (          String name : fileNames) {
            new File(name).delete();
          }
        }
        if (!success)         throw new Exception("String_Node_Str");
      }
    }
  }
  finally {
    leaseMo.updateLeaseProgress(100);
    leaseMo.completeLease();
  }
}

Fixed version (ground truth):
public void exportVm(String exportDir,String exportName,boolean packToOva,boolean leaveOvaFileOnly) throws Exception {
  ManagedObjectReference morOvf=_context.getServiceContent().getOvfManager();
  VirtualMachineRuntimeInfo runtimeInfo=getRuntimeInfo();
  HostMO hostMo=new HostMO(_context,runtimeInfo.getHost());
  String hostName=hostMo.getHostName();
  String vmName=getVmName();
  DatacenterMO dcMo=new DatacenterMO(_context,hostMo.getHyperHostDatacenter());
  if (runtimeInfo.getPowerState() != VirtualMachinePowerState.POWERED_OFF) {
    String msg="String_Node_Str" + vmName + "String_Node_Str"+ hostName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  ManagedObjectReference morLease=_context.getService().exportVm(getMor());
  if (morLease == null) {
    s_logger.error("String_Node_Str");
    throw new Exception("String_Node_Str");
  }
  HttpNfcLeaseMO leaseMo=new HttpNfcLeaseMO(_context,morLease);
  HttpNfcLeaseState state=leaseMo.waitState(new HttpNfcLeaseState[]{HttpNfcLeaseState.READY,HttpNfcLeaseState.ERROR});
  try {
    if (state == HttpNfcLeaseState.READY) {
      final HttpNfcLeaseMO.ProgressReporter progressReporter=leaseMo.createProgressReporter();
      boolean success=false;
      List<String> fileNames=new ArrayList<String>();
      try {
        HttpNfcLeaseInfo leaseInfo=leaseMo.getLeaseInfo();
        final long totalBytes=leaseInfo.getTotalDiskCapacityInKB() * 1024;
        long totalBytesDownloaded=0;
        List<HttpNfcLeaseDeviceUrl> deviceUrls=leaseInfo.getDeviceUrl();
        s_logger.info("String_Node_Str" + System.currentTimeMillis());
        if (deviceUrls != null) {
          OvfFile[] ovfFiles=new OvfFile[deviceUrls.size()];
          for (int i=0; i < deviceUrls.size(); i++) {
            String deviceId=deviceUrls.get(i).getKey();
            String deviceUrlStr=deviceUrls.get(i).getUrl();
            String orgDiskFileName=deviceUrlStr.substring(deviceUrlStr.lastIndexOf("String_Node_Str") + 1);
            String diskFileName=String.format("String_Node_Str",exportName,i,VmwareHelper.getFileExtension(orgDiskFileName,"String_Node_Str"));
            String diskUrlStr=deviceUrlStr.replace("String_Node_Str",hostName);
            diskUrlStr=HypervisorHostHelper.resolveHostNameInUrl(dcMo,diskUrlStr);
            String diskLocalPath=exportDir + File.separator + diskFileName;
            fileNames.add(diskLocalPath);
            if (s_logger.isInfoEnabled()) {
              s_logger.info("String_Node_Str" + deviceUrlStr);
            }
            long lengthOfDiskFile=_context.downloadVmdkFile(diskUrlStr,diskLocalPath,totalBytesDownloaded,new ActionDelegate<Long>(){
              @Override public void action(              Long param){
                if (s_logger.isTraceEnabled()) {
                  s_logger.trace("String_Node_Str" + param + "String_Node_Str"+ totalBytes);
                }
                progressReporter.reportProgress((int)(param * 100 / totalBytes));
              }
            }
);
            totalBytesDownloaded+=lengthOfDiskFile;
            OvfFile ovfFile=new OvfFile();
            ovfFile.setPath(diskFileName);
            ovfFile.setDeviceId(deviceId);
            ovfFile.setSize(lengthOfDiskFile);
            ovfFiles[i]=ovfFile;
          }
          OvfCreateDescriptorParams ovfDescParams=new OvfCreateDescriptorParams();
          ovfDescParams.getOvfFiles().addAll(Arrays.asList(ovfFiles));
          OvfCreateDescriptorResult ovfCreateDescriptorResult=_context.getService().createDescriptor(morOvf,getMor(),ovfDescParams);
          String ovfPath=exportDir + File.separator + exportName+ "String_Node_Str";
          fileNames.add(ovfPath);
          OutputStreamWriter out=new OutputStreamWriter(new FileOutputStream(ovfPath),"String_Node_Str");
          out.write(ovfCreateDescriptorResult.getOvfDescriptor());
          out.close();
          if (packToOva) {
            s_logger.info("String_Node_Str");
            Script commandSync=new Script(true,"String_Node_Str",0,s_logger);
            commandSync.execute();
            Script command=new Script(false,"String_Node_Str",0,s_logger);
            command.setWorkDir(exportDir);
            command.add("String_Node_Str",exportName + "String_Node_Str");
            command.add(exportName + "String_Node_Str");
            for (            String name : fileNames) {
              command.add((new File(name).getName()));
            }
            s_logger.info("String_Node_Str" + command.toString());
            command.execute();
            if ((new File(exportDir + File.separator + exportName+ "String_Node_Str")).exists()) {
              success=true;
            }
 else {
              s_logger.error(exportDir + File.separator + exportName+ "String_Node_Str");
            }
          }
 else {
            success=true;
          }
        }
        s_logger.info("String_Node_Str" + System.currentTimeMillis());
      }
 catch (      Throwable e) {
        s_logger.error("String_Node_Str",e);
      }
 finally {
        progressReporter.close();
        if (leaveOvaFileOnly) {
          for (          String name : fileNames) {
            new File(name).delete();
          }
        }
        if (!success)         throw new Exception("String_Node_Str");
      }
    }
  }
  finally {
    leaseMo.updateLeaseProgress(100);
    leaseMo.completeLease();
  }
}