Source:
<code>public Snapshot prepareSnapshotConfigWithAlternateImage(Snapshot snapshot, Guid oldImageId, DiskImage newImage, OvfManager ovfManager) { <START> if (snapshot != null) { <END> try { String snapConfig = snapshot.getVmConfiguration(); if (snapshot.isVmConfigurationAvailable() && snapConfig != null) { VM vmSnapshot = new VM(); FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vmSnapshot); ovfManager.importVm(snapConfig, vmSnapshot, fullEntityOvfData); Iterator<DiskImage> diskIter = fullEntityOvfData.getDiskImages().iterator(); while (diskIter.hasNext()) { DiskImage imageInList = diskIter.next(); if (imageInList.getImageId().equals(oldImageId)) { log.debug("Recreating vmSnapshot '{}' without the image '{}'", snapshot.getId(), oldImageId); diskIter.remove(); break; } } if (newImage != null) { log.debug("Adding image '{}' to vmSnapshot '{}'", newImage.getImageId(), snapshot.getId()); newImage.setDiskVmElements(Collections.singletonList(diskVmElementDao.get(new VmDeviceId( newImage.getId(), vmSnapshot.getId())))); fullEntityOvfData.getDiskImages().add(newImage); } final Version compatibilityVersion = Optional.ofNullable(vmSnapshot.getStaticData().getClusterCompatibilityVersionOrigin()) .orElse(Version.getLowest()); FullEntityOvfData fullEntityOvfDataForExport = new FullEntityOvfData(vmSnapshot); fullEntityOvfDataForExport.setDiskImages(fullEntityOvfData.getDiskImages()); String newOvf = ovfManager.exportVm(vmSnapshot, fullEntityOvfDataForExport, compatibilityVersion); snapshot.setVmConfiguration(newOvf); } } catch (OvfReaderException e) { log.error("Can't remove image '{}' from snapshot '{}'", oldImageId, snapshot.getId()); } } return snapshot; }</code><technical_language>early return instead? this patch smaller method more readable if (snapshot == null) { return null; }</technical_language>

Target:
public Snapshot prepareSnapshotConfigWithAlternateImage(Snapshot snapshot, Guid oldImageId, DiskImage newImage, OvfManager ovfManager) { if (snapshot == null) { return null; } try { String snapConfig = snapshot.getVmConfiguration(); if (snapshot.isVmConfigurationAvailable() && snapConfig != null) { VM vmSnapshot = new VM(); FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vmSnapshot); ovfManager.importVm(snapConfig, vmSnapshot, fullEntityOvfData); Iterator<DiskImage> diskIter = fullEntityOvfData.getDiskImages().iterator(); while (diskIter.hasNext()) { DiskImage imageInList = diskIter.next(); if (imageInList.getImageId().equals(oldImageId)) { log.debug("Recreating vmSnapshot '{}' without the image '{}'", snapshot.getId(), oldImageId); diskIter.remove(); break; } } if (newImage != null) { log.debug("Adding image '{}' to vmSnapshot '{}'", newImage.getImageId(), snapshot.getId()); newImage.setDiskVmElements(Collections.singletonList(diskVmElementDao.get(new VmDeviceId(newImage.getId(), vmSnapshot.getId())))); fullEntityOvfData.getDiskImages().add(newImage); } final Version compatibilityVersion = Optional.ofNullable(vmSnapshot.getStaticData().getClusterCompatibilityVersionOrigin()) .orElse(Version.getLowest()); FullEntityOvfData fullEntityOvfDataForExport = new FullEntityOvfData(vmSnapshot); fullEntityOvfDataForExport.setDiskImages(fullEntityOvfData.getDiskImages()); String newOvf = ovfManager.exportVm(vmSnapshot, fullEntityOvfDataForExport, compatibilityVersion); snapshot.setVmConfiguration(newOvf); } } catch (OvfReaderException e) { log.error("Can't remove image '{}' from snapshot '{}'", oldImageId, snapshot.getId()); } return snapshot; }