Program: 14287
Project: 14287
Buggy source:
private void setupVolumeMessages() throws NoSuchElementException, MetadataException, ExecutionException {
  if (this.allocInfo.getBootSet().getMachine() instanceof BlockStorageImageInfo) {
    List<BlockDeviceMappingItemType> instanceDeviceMappings=new ArrayList<BlockDeviceMappingItemType>(this.allocInfo.getRequest().getBlockDeviceMapping());
    final ServiceConfiguration sc=Topology.lookup(Storage.class,this.cluster.getConfiguration().lookupPartition());
    final BlockStorageImageInfo imgInfo=((BlockStorageImageInfo)this.allocInfo.getBootSet().getMachine());
    String rootDevName=imgInfo.getRootDeviceName();
    Long volSizeBytes=imgInfo.getImageSizeBytes();
    for (    final BlockDeviceMappingItemType blockDevMapping : Iterables.filter(instanceDeviceMappings,findEbsRootOptionalSnapshot(rootDevName))) {
      if (blockDevMapping.getEbs().getVolumeSize() != null) {
        volSizeBytes=BYTES_PER_GB * blockDevMapping.getEbs().getVolumeSize();
      }
    }
    int rootVolSizeInGb=(int)Math.ceil(volSizeBytes / BYTES_PER_GB);
    for (    final ResourceToken token : this.allocInfo.getAllocationTokens()) {
      final VmInstance vm=VmInstances.lookup(token.getInstanceId());
      if (!vm.getBootRecord().hasPersistentVolumes()) {
        for (        BlockDeviceMappingItemType mapping : instanceDeviceMappings) {
          if (Images.isEbsMapping(mapping)) {
            LOG.debug("String_Node_Str" + vm.getDisplayName() + "String_Node_Str"+ mapping.getDeviceName()+ "String_Node_Str");
            final Volume volume=Volumes.createStorageVolume(sc,this.allocInfo.getOwnerFullName(),mapping.getEbs().getSnapshotId(),mapping.getEbs().getVolumeSize() != null ? mapping.getEbs().getVolumeSize() : (mapping.getEbs().getSnapshotId() != null ? -1 : rootVolSizeInGb),this.allocInfo.getRequest());
            Boolean isRootDevice=mapping.getDeviceName().equals(rootDevName);
            if (mapping.getEbs().getDeleteOnTermination()) {
              vm.addPersistentVolume(mapping.getDeviceName(),volume,isRootDevice);
            }
 else {
              vm.addPermanentVolume(mapping.getDeviceName(),volume,isRootDevice);
            }
            if (isRootDevice) {
              token.setRootVolume(volume);
            }
 else {
              token.getEbsVolumes().put(mapping.getDeviceName(),volume);
            }
          }
 else           if (mapping.getVirtualName() != null) {
            vm.addEphemeralAttachment(mapping.getDeviceName(),mapping.getVirtualName());
            token.getEphemeralDisks().put(mapping.getDeviceName(),mapping.getVirtualName());
          }
        }
      }
 else {
        boolean foundRoot=false;
        for (        VmVolumeAttachment attachment : vm.getBootRecord().getPersistentVolumes()) {
          final Volume volume=Volumes.lookup(null,attachment.getVolumeId());
          if (attachment.getIsRootDevice() || attachment.getDevice().equals(rootDevName)) {
            token.setRootVolume(volume);
            foundRoot=true;
          }
 else {
            token.getEbsVolumes().put(attachment.getDevice(),volume);
          }
        }
        if (!foundRoot) {
          LOG.error("String_Node_Str");
          throw new MetadataException("String_Node_Str");
        }
        for (        VmEphemeralAttachment attachment : vm.getBootRecord().getEphmeralStorage()) {
          token.getEphemeralDisks().put(attachment.getDevice(),attachment.getEphemeralId());
        }
      }
    }
  }
}

Fixed version (ground truth):
private void setupVolumeMessages() throws NoSuchElementException, MetadataException, ExecutionException {
  if (this.allocInfo.getBootSet().getMachine() instanceof BlockStorageImageInfo) {
    List<BlockDeviceMappingItemType> instanceDeviceMappings=new ArrayList<BlockDeviceMappingItemType>(this.allocInfo.getRequest().getBlockDeviceMapping());
    final ServiceConfiguration sc=Topology.lookup(Storage.class,this.cluster.getConfiguration().lookupPartition());
    final BlockStorageImageInfo imgInfo=((BlockStorageImageInfo)this.allocInfo.getBootSet().getMachine());
    String rootDevName=imgInfo.getRootDeviceName();
    Long volSizeBytes=imgInfo.getImageSizeBytes();
    for (    final BlockDeviceMappingItemType blockDevMapping : Iterables.filter(instanceDeviceMappings,findEbsRootOptionalSnapshot(rootDevName))) {
      if (blockDevMapping.getEbs().getVolumeSize() != null) {
        volSizeBytes=BYTES_PER_GB * blockDevMapping.getEbs().getVolumeSize();
      }
    }
    int rootVolSizeInGb=(int)Math.ceil(((double)volSizeBytes) / BYTES_PER_GB);
    for (    final ResourceToken token : this.allocInfo.getAllocationTokens()) {
      final VmInstance vm=VmInstances.lookup(token.getInstanceId());
      if (!vm.getBootRecord().hasPersistentVolumes()) {
        for (        BlockDeviceMappingItemType mapping : instanceDeviceMappings) {
          if (Images.isEbsMapping(mapping)) {
            LOG.debug("String_Node_Str" + vm.getDisplayName() + "String_Node_Str"+ mapping.getDeviceName()+ "String_Node_Str");
            final Volume volume=Volumes.createStorageVolume(sc,this.allocInfo.getOwnerFullName(),mapping.getEbs().getSnapshotId(),mapping.getEbs().getVolumeSize() != null ? mapping.getEbs().getVolumeSize() : (mapping.getEbs().getSnapshotId() != null ? -1 : rootVolSizeInGb),this.allocInfo.getRequest());
            Boolean isRootDevice=mapping.getDeviceName().equals(rootDevName);
            if (mapping.getEbs().getDeleteOnTermination()) {
              vm.addPersistentVolume(mapping.getDeviceName(),volume,isRootDevice);
            }
 else {
              vm.addPermanentVolume(mapping.getDeviceName(),volume,isRootDevice);
            }
            if (isRootDevice) {
              token.setRootVolume(volume);
            }
 else {
              token.getEbsVolumes().put(mapping.getDeviceName(),volume);
            }
          }
 else           if (mapping.getVirtualName() != null) {
            vm.addEphemeralAttachment(mapping.getDeviceName(),mapping.getVirtualName());
            token.getEphemeralDisks().put(mapping.getDeviceName(),mapping.getVirtualName());
          }
        }
      }
 else {
        boolean foundRoot=false;
        for (        VmVolumeAttachment attachment : vm.getBootRecord().getPersistentVolumes()) {
          final Volume volume=Volumes.lookup(null,attachment.getVolumeId());
          if (attachment.getIsRootDevice() || attachment.getDevice().equals(rootDevName)) {
            token.setRootVolume(volume);
            foundRoot=true;
          }
 else {
            token.getEbsVolumes().put(attachment.getDevice(),volume);
          }
        }
        if (!foundRoot) {
          LOG.error("String_Node_Str");
          throw new MetadataException("String_Node_Str");
        }
        for (        VmEphemeralAttachment attachment : vm.getBootRecord().getEphmeralStorage()) {
          token.getEphemeralDisks().put(attachment.getDevice(),attachment.getEphemeralId());
        }
      }
    }
  }
}