Program: 106157
Project: 106157
Buggy source:
@Override public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd){
  DataTO srcData=cmd.getSrcTO();
  DataTO destData=cmd.getDestTO();
  TemplateObjectTO template=(TemplateObjectTO)srcData;
  DataStoreTO imageStore=template.getDataStore();
  VolumeObjectTO volume=(VolumeObjectTO)destData;
  PrimaryDataStoreTO primaryStore=(PrimaryDataStoreTO)volume.getDataStore();
  KVMPhysicalDisk BaseVol=null;
  KVMStoragePool primaryPool=null;
  KVMPhysicalDisk vol=null;
  try {
    primaryPool=storagePoolMgr.getStoragePool(primaryStore.getPoolType(),primaryStore.getUuid());
    String templatePath=template.getPath();
    if (primaryPool.getType() == StoragePoolType.CLVM) {
      templatePath=((NfsTO)imageStore).getUrl() + File.separator + templatePath;
      vol=templateToPrimaryDownload(templatePath,primaryPool);
    }
 else {
      if (templatePath.contains("String_Node_Str")) {
        templatePath=templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
      }
      BaseVol=storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),primaryStore.getUuid(),templatePath);
      vol=storagePoolMgr.createDiskFromTemplate(BaseVol,UUID.randomUUID().toString(),BaseVol.getPool());
    }
    if (vol == null) {
      return new CopyCmdAnswer("String_Node_Str");
    }
    VolumeObjectTO newVol=new VolumeObjectTO();
    newVol.setPath(vol.getName());
    newVol.setSize(volume.getSize());
    if (vol.getFormat() == PhysicalDiskFormat.RAW) {
      newVol.setFormat(ImageFormat.RAW);
    }
 else     if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
      newVol.setFormat(ImageFormat.QCOW2);
    }
    return new CopyCmdAnswer(newVol);
  }
 catch (  CloudRuntimeException e) {
    s_logger.debug("String_Node_Str" + e.toString());
    return new CopyCmdAnswer(e.toString());
  }
}

Fixed version (ground truth):
@Override public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd){
  DataTO srcData=cmd.getSrcTO();
  DataTO destData=cmd.getDestTO();
  TemplateObjectTO template=(TemplateObjectTO)srcData;
  DataStoreTO imageStore=template.getDataStore();
  VolumeObjectTO volume=(VolumeObjectTO)destData;
  PrimaryDataStoreTO primaryStore=(PrimaryDataStoreTO)volume.getDataStore();
  KVMPhysicalDisk BaseVol=null;
  KVMStoragePool primaryPool=null;
  KVMPhysicalDisk vol=null;
  try {
    primaryPool=storagePoolMgr.getStoragePool(primaryStore.getPoolType(),primaryStore.getUuid());
    String templatePath=template.getPath();
    if (primaryPool.getType() == StoragePoolType.CLVM) {
      templatePath=((NfsTO)imageStore).getUrl() + File.separator + templatePath;
      vol=templateToPrimaryDownload(templatePath,primaryPool,cmd.getWaitInMillSeconds());
    }
 else {
      if (templatePath.contains("String_Node_Str")) {
        templatePath=templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
      }
      BaseVol=storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),primaryStore.getUuid(),templatePath);
      vol=storagePoolMgr.createDiskFromTemplate(BaseVol,UUID.randomUUID().toString(),BaseVol.getPool(),cmd.getWaitInMillSeconds());
    }
    if (vol == null) {
      return new CopyCmdAnswer("String_Node_Str");
    }
    VolumeObjectTO newVol=new VolumeObjectTO();
    newVol.setPath(vol.getName());
    newVol.setSize(volume.getSize());
    if (vol.getFormat() == PhysicalDiskFormat.RAW) {
      newVol.setFormat(ImageFormat.RAW);
    }
 else     if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
      newVol.setFormat(ImageFormat.QCOW2);
    }
    return new CopyCmdAnswer(newVol);
  }
 catch (  CloudRuntimeException e) {
    s_logger.debug("String_Node_Str" + e.toString());
    return new CopyCmdAnswer(e.toString());
  }
}