Program: 105127
Project: 105127
Buggy source:
@Override public Answer createVolumeFromSnapshot(final CopyCommand cmd){
  final Connection conn=hypervisorResource.getConnection();
  final DataTO srcData=cmd.getSrcTO();
  final SnapshotObjectTO snapshot=(SnapshotObjectTO)srcData;
  final DataTO destData=cmd.getDestTO();
  final PrimaryDataStoreTO pool=(PrimaryDataStoreTO)destData.getDataStore();
  final VolumeObjectTO volume=(VolumeObjectTO)destData;
  final DataStoreTO imageStore=srcData.getDataStore();
  if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof PrimaryDataStoreTO) {
    return createVolumeFromSnapshot2(cmd);
  }
  if (!(imageStore instanceof NfsTO)) {
    return new CopyCmdAnswer("String_Node_Str");
  }
  final NfsTO nfsImageStore=(NfsTO)imageStore;
  final String primaryStorageNameLabel=pool.getUuid();
  final String secondaryStorageUrl=nfsImageStore.getUrl();
  final int wait=cmd.getWait();
  boolean result=false;
  String details=null;
  String volumeUUID=null;
  if (secondaryStorageUrl == null) {
    details+="String_Node_Str" + secondaryStorageUrl + "String_Node_Str";
    return new CopyCmdAnswer(details);
  }
  SR srcSr=null;
  VDI destVdi=null;
  try {
    final SR primaryStorageSR=hypervisorResource.getSRByNameLabelandHost(conn,primaryStorageNameLabel);
    if (primaryStorageSR == null) {
      throw new InternalErrorException("String_Node_Str" + primaryStorageNameLabel);
    }
    final String nameLabel="String_Node_Str" + UUID.randomUUID().toString();
    destVdi=createVdi(conn,nameLabel,primaryStorageSR,volume.getSize());
    volumeUUID=destVdi.getUuid(conn);
    final String snapshotInstallPath=snapshot.getPath();
    final int index=snapshotInstallPath.lastIndexOf(File.separator);
    final String snapshotDirectory=snapshotInstallPath.substring(0,index);
    final String snapshotUuid=getSnapshotUuid(snapshotInstallPath);
    final URI uri=new URI(secondaryStorageUrl);
    srcSr=createFileSr(conn,uri.getHost() + "String_Node_Str" + uri.getPath(),snapshotDirectory);
    final String[] parents=snapshot.getParents();
    final List<VDI> snapshotChains=new ArrayList<VDI>();
    if (parents != null) {
      for (int i=0; i < parents.length; i++) {
        final String snChainPath=parents[i];
        final String uuid=getSnapshotUuid(snChainPath);
        final VDI chain=VDI.getByUuid(conn,uuid);
        snapshotChains.add(chain);
      }
    }
    final VDI snapshotVdi=VDI.getByUuid(conn,snapshotUuid);
    snapshotChains.add(snapshotVdi);
    for (    final VDI snapChain : snapshotChains) {
      final Task task=snapChain.copyAsync(conn,null,null,destVdi);
      hypervisorResource.waitForTask(conn,task,1000,wait * 1000);
      hypervisorResource.checkForSuccess(conn,task);
      task.destroy(conn);
    }
    result=true;
    destVdi=VDI.getByUuid(conn,volumeUUID);
    final VDI.Record vdir=destVdi.getRecord(conn);
    final VolumeObjectTO newVol=new VolumeObjectTO();
    newVol.setPath(volumeUUID);
    newVol.setSize(vdir.virtualSize);
    return new CopyCmdAnswer(newVol);
  }
 catch (  final Types.XenAPIException e) {
    details+="String_Node_Str" + e.toString();
    s_logger.warn(details,e);
  }
catch (  final Exception e) {
    details+="String_Node_Str" + e.getMessage();
    s_logger.warn(details,e);
  }
 finally {
    if (srcSr != null) {
      hypervisorResource.removeSR(conn,srcSr);
    }
    if (!result && destVdi != null) {
      try {
        destVdi.destroy(conn);
      }
 catch (      final Exception e) {
        s_logger.debug("String_Node_Str",e);
      }
    }
  }
  if (!result) {
    s_logger.error(details);
  }
  return new CopyCmdAnswer(details);
}

Fixed version (ground truth):
@Override public Answer createVolumeFromSnapshot(final CopyCommand cmd){
  final Connection conn=hypervisorResource.getConnection();
  final DataTO srcData=cmd.getSrcTO();
  final SnapshotObjectTO snapshot=(SnapshotObjectTO)srcData;
  final DataTO destData=cmd.getDestTO();
  final PrimaryDataStoreTO pool=(PrimaryDataStoreTO)destData.getDataStore();
  final VolumeObjectTO volume=(VolumeObjectTO)destData;
  final DataStoreTO imageStore=srcData.getDataStore();
  if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof PrimaryDataStoreTO) {
    return createVolumeFromSnapshot2(cmd);
  }
  if (!(imageStore instanceof NfsTO)) {
    return new CopyCmdAnswer("String_Node_Str");
  }
  final NfsTO nfsImageStore=(NfsTO)imageStore;
  final String primaryStorageNameLabel=pool.getUuid();
  final String secondaryStorageUrl=nfsImageStore.getUrl();
  final int wait=cmd.getWait();
  boolean result=false;
  String details=null;
  String volumeUUID=null;
  if (secondaryStorageUrl == null) {
    details+="String_Node_Str" + secondaryStorageUrl + "String_Node_Str";
    return new CopyCmdAnswer(details);
  }
  SR srcSr=null;
  VDI destVdi=null;
  try {
    final SR primaryStorageSR=hypervisorResource.getSRByNameLabelandHost(conn,primaryStorageNameLabel);
    if (primaryStorageSR == null) {
      throw new InternalErrorException("String_Node_Str" + primaryStorageNameLabel);
    }
    final String nameLabel="String_Node_Str" + UUID.randomUUID().toString();
    destVdi=createVdi(conn,nameLabel,primaryStorageSR,volume.getSize());
    volumeUUID=destVdi.getUuid(conn);
    final String snapshotInstallPath=snapshot.getPath();
    final int index=snapshotInstallPath.lastIndexOf(File.separator);
    final String snapshotDirectory=snapshotInstallPath.substring(0,index);
    final String snapshotUuid=getSnapshotUuid(snapshotInstallPath);
    final URI uri=new URI(secondaryStorageUrl);
    srcSr=createFileSr(conn,uri.getHost() + "String_Node_Str" + uri.getPath(),snapshotDirectory);
    final String[] parents=snapshot.getParents();
    final List<VDI> snapshotChains=new ArrayList<VDI>();
    if (parents != null) {
      for (int i=0; i < parents.length; i++) {
        final String snChainPath=parents[i];
        final String uuid=getSnapshotUuid(snChainPath);
        final VDI chain=VDI.getByUuid(conn,uuid);
        snapshotChains.add(chain);
      }
    }
    final VDI snapshotVdi=VDI.getByUuid(conn,snapshotUuid);
    snapshotChains.add(snapshotVdi);
    for (    final VDI snapChain : snapshotChains) {
      final Task task=snapChain.copyAsync(conn,null,null,destVdi);
      hypervisorResource.waitForTask(conn,task,1000,wait * 1000);
      hypervisorResource.checkForSuccess(conn,task);
      task.destroy(conn);
    }
    result=true;
    destVdi=VDI.getByUuid(conn,volumeUUID);
    final VDI.Record vdir=destVdi.getRecord(conn);
    final VolumeObjectTO newVol=new VolumeObjectTO();
    newVol.setPath(volumeUUID);
    newVol.setSize(vdir.virtualSize);
    return new CopyCmdAnswer(newVol);
  }
 catch (  final Types.XenAPIException e) {
    details+="String_Node_Str" + e.toString();
    s_logger.warn(details,e);
  }
catch (  final Exception e) {
    details+="String_Node_Str" + e.getMessage();
    s_logger.warn(details,e);
  }
 finally {
    if (srcSr != null) {
      hypervisorResource.skipOrRemoveSR(conn,srcSr);
    }
    if (!result && destVdi != null) {
      try {
        destVdi.destroy(conn);
      }
 catch (      final Exception e) {
        s_logger.debug("String_Node_Str",e);
      }
    }
  }
  if (!result) {
    s_logger.error(details);
  }
  return new CopyCmdAnswer(details);
}