Program: 106155
Project: 106155
Buggy source:
@Override public Answer createTemplateFromVolume(CopyCommand cmd){
  DataTO srcData=cmd.getSrcTO();
  DataTO destData=cmd.getDestTO();
  int wait=cmd.getWait();
  TemplateObjectTO template=(TemplateObjectTO)destData;
  DataStoreTO imageStore=template.getDataStore();
  VolumeObjectTO volume=(VolumeObjectTO)srcData;
  PrimaryDataStoreTO primaryStore=(PrimaryDataStoreTO)volume.getDataStore();
  if (!(imageStore instanceof NfsTO)) {
    return new CopyCmdAnswer("String_Node_Str");
  }
  NfsTO nfsImageStore=(NfsTO)imageStore;
  KVMStoragePool secondaryStorage=null;
  KVMStoragePool primary=null;
  try {
    String templateFolder=template.getPath();
    secondaryStorage=storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl());
    primary=storagePoolMgr.getStoragePool(primaryStore.getPoolType(),primaryStore.getUuid());
    KVMPhysicalDisk disk=storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),primaryStore.getUuid(),volume.getPath());
    String tmpltPath=secondaryStorage.getLocalPath() + File.separator + templateFolder;
    this.storageLayer.mkdirs(tmpltPath);
    String templateName=UUID.randomUUID().toString();
    if (primary.getType() != StoragePoolType.RBD) {
      Script command=new Script(_createTmplPath,wait * 1000,s_logger);
      command.add("String_Node_Str",disk.getPath());
      command.add("String_Node_Str",tmpltPath);
      command.add("String_Node_Str",templateName + "String_Node_Str");
      String result=command.execute();
      if (result != null) {
        s_logger.debug("String_Node_Str" + result);
        return new CopyCmdAnswer(result);
      }
    }
 else {
      s_logger.debug("String_Node_Str" + disk.getPath() + "String_Node_Str"+ templateName);
      QemuImgFile srcFile=new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),primary.getSourcePort(),primary.getAuthUserName(),primary.getAuthSecret(),disk.getPath()));
      srcFile.setFormat(PhysicalDiskFormat.RAW);
      QemuImgFile destFile=new QemuImgFile(tmpltPath + "String_Node_Str" + templateName+ "String_Node_Str");
      destFile.setFormat(PhysicalDiskFormat.QCOW2);
      QemuImg q=new QemuImg();
      try {
        q.convert(srcFile,destFile);
      }
 catch (      QemuImgException e) {
        s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      }
      File templateProp=new File(tmpltPath + "String_Node_Str");
      if (!templateProp.exists()) {
        templateProp.createNewFile();
      }
      String templateContent="String_Node_Str" + templateName + "String_Node_Str"+ System.getProperty("String_Node_Str");
      DateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
      Date date=new Date();
      templateContent+="String_Node_Str" + dateFormat.format(date) + System.getProperty("String_Node_Str");
      FileOutputStream templFo=new FileOutputStream(templateProp);
      templFo.write(templateContent.getBytes());
      templFo.flush();
      templFo.close();
    }
    Map<String,Object> params=new HashMap<String,Object>();
    params.put(StorageLayer.InstanceConfigKey,this.storageLayer);
    Processor qcow2Processor=new QCOW2Processor();
    qcow2Processor.configure("String_Node_Str",params);
    FormatInfo info=qcow2Processor.process(tmpltPath,null,templateName);
    TemplateLocation loc=new TemplateLocation(this.storageLayer,tmpltPath);
    loc.create(1,true,templateName);
    loc.addFormat(info);
    loc.save();
    TemplateObjectTO newTemplate=new TemplateObjectTO();
    newTemplate.setPath(templateFolder + File.separator + templateName+ "String_Node_Str");
    newTemplate.setSize(info.virtualSize);
    newTemplate.setPhysicalSize(info.size);
    newTemplate.setFormat(ImageFormat.QCOW2);
    newTemplate.setName(templateName);
    return new CopyCmdAnswer(newTemplate);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str" + e.toString());
    return new CopyCmdAnswer(e.toString());
  }
 finally {
    if (secondaryStorage != null) {
      secondaryStorage.delete();
    }
  }
}

Fixed version (ground truth):
@Override public Answer createTemplateFromVolume(CopyCommand cmd){
  DataTO srcData=cmd.getSrcTO();
  DataTO destData=cmd.getDestTO();
  int wait=cmd.getWaitInMillSeconds();
  TemplateObjectTO template=(TemplateObjectTO)destData;
  DataStoreTO imageStore=template.getDataStore();
  VolumeObjectTO volume=(VolumeObjectTO)srcData;
  PrimaryDataStoreTO primaryStore=(PrimaryDataStoreTO)volume.getDataStore();
  if (!(imageStore instanceof NfsTO)) {
    return new CopyCmdAnswer("String_Node_Str");
  }
  NfsTO nfsImageStore=(NfsTO)imageStore;
  KVMStoragePool secondaryStorage=null;
  KVMStoragePool primary=null;
  try {
    String templateFolder=template.getPath();
    secondaryStorage=storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl());
    primary=storagePoolMgr.getStoragePool(primaryStore.getPoolType(),primaryStore.getUuid());
    KVMPhysicalDisk disk=storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),primaryStore.getUuid(),volume.getPath());
    String tmpltPath=secondaryStorage.getLocalPath() + File.separator + templateFolder;
    this.storageLayer.mkdirs(tmpltPath);
    String templateName=UUID.randomUUID().toString();
    if (primary.getType() != StoragePoolType.RBD) {
      Script command=new Script(_createTmplPath,wait,s_logger);
      command.add("String_Node_Str",disk.getPath());
      command.add("String_Node_Str",tmpltPath);
      command.add("String_Node_Str",templateName + "String_Node_Str");
      String result=command.execute();
      if (result != null) {
        s_logger.debug("String_Node_Str" + result);
        return new CopyCmdAnswer(result);
      }
    }
 else {
      s_logger.debug("String_Node_Str" + disk.getPath() + "String_Node_Str"+ templateName);
      QemuImgFile srcFile=new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),primary.getSourcePort(),primary.getAuthUserName(),primary.getAuthSecret(),disk.getPath()));
      srcFile.setFormat(PhysicalDiskFormat.RAW);
      QemuImgFile destFile=new QemuImgFile(tmpltPath + "String_Node_Str" + templateName+ "String_Node_Str");
      destFile.setFormat(PhysicalDiskFormat.QCOW2);
      QemuImg q=new QemuImg(cmd.getWaitInMillSeconds());
      try {
        q.convert(srcFile,destFile);
      }
 catch (      QemuImgException e) {
        s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      }
      File templateProp=new File(tmpltPath + "String_Node_Str");
      if (!templateProp.exists()) {
        templateProp.createNewFile();
      }
      String templateContent="String_Node_Str" + templateName + "String_Node_Str"+ System.getProperty("String_Node_Str");
      DateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
      Date date=new Date();
      templateContent+="String_Node_Str" + dateFormat.format(date) + System.getProperty("String_Node_Str");
      FileOutputStream templFo=new FileOutputStream(templateProp);
      templFo.write(templateContent.getBytes());
      templFo.flush();
      templFo.close();
    }
    Map<String,Object> params=new HashMap<String,Object>();
    params.put(StorageLayer.InstanceConfigKey,this.storageLayer);
    Processor qcow2Processor=new QCOW2Processor();
    qcow2Processor.configure("String_Node_Str",params);
    FormatInfo info=qcow2Processor.process(tmpltPath,null,templateName);
    TemplateLocation loc=new TemplateLocation(this.storageLayer,tmpltPath);
    loc.create(1,true,templateName);
    loc.addFormat(info);
    loc.save();
    TemplateObjectTO newTemplate=new TemplateObjectTO();
    newTemplate.setPath(templateFolder + File.separator + templateName+ "String_Node_Str");
    newTemplate.setSize(info.virtualSize);
    newTemplate.setPhysicalSize(info.size);
    newTemplate.setFormat(ImageFormat.QCOW2);
    newTemplate.setName(templateName);
    return new CopyCmdAnswer(newTemplate);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str" + e.toString());
    return new CopyCmdAnswer(e.toString());
  }
 finally {
    if (secondaryStorage != null) {
      secondaryStorage.delete();
    }
  }
}