Program: 15327
Project: 15327
Buggy source:
public static ImageInfo createFromDeviceMapping(UserFullName userFullName,String imageName,String imageDescription,String eki,String eri,String rootDeviceName,final List<BlockDeviceMappingItemType> blockDeviceMappings) throws EucalyptusCloudException {
  Context ctx=Contexts.lookup();
  Image.Architecture imageArch=Image.Architecture.x86_64;
  Image.Platform imagePlatform=Image.Platform.linux;
  BlockDeviceMappingItemType rootBlockDevice=Iterables.find(blockDeviceMappings,findEbsRoot(rootDeviceName));
  String snapshotId=rootBlockDevice.getEbs().getSnapshotId();
  try {
    Snapshot snap=Snapshots.lookup(userFullName,snapshotId);
    if (!userFullName.getUserId().equals(snap.getOwnerUserId())) {
      throw new EucalyptusCloudException("String_Node_Str" + rootBlockDevice + "String_Node_Str");
    }
    Integer snapVolumeSize=snap.getVolumeSize();
    Integer suppliedVolumeSize=(rootBlockDevice.getEbs().getVolumeSize() != null) ? rootBlockDevice.getEbs().getVolumeSize() : -1;
    suppliedVolumeSize=(suppliedVolumeSize == null) ? rootBlockDevice.getSize() : suppliedVolumeSize;
    Integer targetVolumeSizeGB=(snapVolumeSize <= suppliedVolumeSize) ? suppliedVolumeSize : snapVolumeSize;
    Long imageSizeBytes=targetVolumeSizeGB * 1024l * 1024l* 1024l;
    Boolean targetDeleteOnTermination=Boolean.TRUE.equals(rootBlockDevice.getEbs().getDeleteOnTermination());
    String imageId=generateImageId(Image.Type.machine.getTypePrefix(),snapshotId);
    BlockStorageImageInfo ret=new BlockStorageImageInfo(userFullName,imageId,imageName,imageDescription,imageSizeBytes,imageArch,imagePlatform,eki,eri,snap.getDisplayName(),targetDeleteOnTermination);
    ret=Transactions.save(ret,new Callback<BlockStorageImageInfo>(){
      @Override public void fire(      BlockStorageImageInfo t){
        t.getDeviceMappings().addAll(Lists.transform(blockDeviceMappings,Images.deviceMappingGenerator(t)));
      }
    }
);
    return ret;
  }
 catch (  TransactionFireException ex) {
    throw new EucalyptusCloudException("String_Node_Str" + rootBlockDevice + "String_Node_Str"+ ex.getMessage());
  }
catch (  ExecutionException ex) {
    LOG.error(ex,ex);
    throw new EucalyptusCloudException("String_Node_Str" + rootBlockDevice + "String_Node_Str"+ ex.getMessage());
  }
}

Fixed version (ground truth):
public static ImageInfo createFromDeviceMapping(UserFullName userFullName,String imageName,String imageDescription,String eki,String eri,String rootDeviceName,final List<BlockDeviceMappingItemType> blockDeviceMappings) throws EucalyptusCloudException {
  Context ctx=Contexts.lookup();
  Image.Architecture imageArch=Image.Architecture.x86_64;
  Image.Platform imagePlatform=Image.Platform.linux;
  BlockDeviceMappingItemType rootBlockDevice=Iterables.find(blockDeviceMappings,findEbsRoot(rootDeviceName));
  String snapshotId=rootBlockDevice.getEbs().getSnapshotId();
  try {
    Snapshot snap=Snapshots.lookup(userFullName,snapshotId);
    if (!userFullName.getUserId().equals(snap.getOwnerUserId())) {
      throw new EucalyptusCloudException("String_Node_Str" + rootBlockDevice + "String_Node_Str");
    }
    Integer snapVolumeSize=snap.getVolumeSize();
    Integer suppliedVolumeSize=(rootBlockDevice.getEbs().getVolumeSize() != null) ? rootBlockDevice.getEbs().getVolumeSize() : -1;
    suppliedVolumeSize=(suppliedVolumeSize == null) ? rootBlockDevice.getSize() : suppliedVolumeSize;
    Integer targetVolumeSizeGB=(snapVolumeSize <= suppliedVolumeSize) ? suppliedVolumeSize : snapVolumeSize;
    Long imageSizeBytes=targetVolumeSizeGB * 1024l * 1024l* 1024l;
    Boolean targetDeleteOnTermination=Boolean.TRUE.equals(rootBlockDevice.getEbs().getDeleteOnTermination());
    String imageId=generateImageId(Image.Type.machine.getTypePrefix(),snapshotId);
    BlockStorageImageInfo ret=new BlockStorageImageInfo(userFullName,imageId,imageName,imageDescription,imageSizeBytes,imageArch,imagePlatform,eki,eri,snap.getDisplayName(),targetDeleteOnTermination);
    EntityWrapper<BlockStorageImageInfo> db=EntityWrapper.get(BlockStorageImageInfo.class);
    try {
      ret=db.merge(ret);
      ret.getDeviceMappings().addAll(Lists.transform(blockDeviceMappings,Images.deviceMappingGenerator(ret)));
      db.commit();
      LOG.info("String_Node_Str" + ret.getDisplayName() + "String_Node_Str"+ userFullName);
    }
 catch (    Exception e) {
      db.rollback();
      throw new EucalyptusCloudException("String_Node_Str" + snapshotId + "String_Node_Str"+ e.getMessage(),e);
    }
    return ret;
  }
 catch (  TransactionFireException ex) {
    throw new EucalyptusCloudException("String_Node_Str" + rootBlockDevice + "String_Node_Str"+ ex.getMessage());
  }
catch (  ExecutionException ex) {
    LOG.error(ex,ex);
    throw new EucalyptusCloudException("String_Node_Str" + rootBlockDevice + "String_Node_Str"+ ex.getMessage());
  }
}