Source:
<code>public NodeMetadata apply(VirtualGuest from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getFullyQualifiedDomainName()); if (from.getDatacenter() != null) { builder.location(from(locations.get()).firstMatch( LocationPredicates.idEquals(from.getDatacenter().getName())).orNull()); } builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname())); builder.hardware(virtualGuestToHardware.apply(from)); Image image = virtualGuestToImage.apply(from); if (image != null) { builder.imageId(image.getId()); builder.operatingSystem(image.getOperatingSystem()); } if (from.getPowerState() != null) { builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName())); } if (from.getPrimaryIpAddress() != null) builder.publicAddresses(ImmutableSet.of(from.getPrimaryIpAddress())); if (from.getPrimaryBackendIpAddress() != null) builder.privateAddresses(ImmutableSet.of(from.getPrimaryBackendIpAddress())); if (from.getOperatingSystem() != null && from.getOperatingSystem().getPasswords() != null && !from.getOperatingSystem().getPasswords().isEmpty()) { Password password = Iterables.getOnlyElement(from.getOperatingSystem().getPasswords()); <START> if (password != null) { <END> builder.credentials(LoginCredentials.builder().identity(password.getUsername()).credential(password.getPassword()).build()); } } if (from.getTagReferences() != null && !from.getTagReferences().isEmpty()) { List<String> tags = Lists.newArrayList(); for (TagReference tagReference : from.getTagReferences()) { if (tagReference != null) { tags.add(tagReference.getTag().getName()); } } builder.tags(tags); } return builder.build(); }</code><technical_language>This null, getOnlyElement fail if is empty more element</technical_language>

Target:
public NodeMetadata apply(VirtualGuest from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); builder.hostname(from.getFullyQualifiedDomainName()); if (from.getDatacenter() != null) { builder.location(from(locations.get()).firstMatch( LocationPredicates.idEquals(from.getDatacenter().getName())).orNull()); } builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname())); builder.hardware(virtualGuestToHardware.apply(from)); Image image = virtualGuestToImage.apply(from); if (image != null) { builder.imageId(image.getId()); builder.operatingSystem(image.getOperatingSystem()); } if (from.getPowerState() != null) { builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName())); } if (from.getPrimaryIpAddress() != null) builder.publicAddresses(ImmutableSet.of(from.getPrimaryIpAddress())); if (from.getPrimaryBackendIpAddress() != null) builder.privateAddresses(ImmutableSet.of(from.getPrimaryBackendIpAddress())); if (from.getOperatingSystem() != null && from.getOperatingSystem().getPasswords() != null && !from.getOperatingSystem().getPasswords().isEmpty()) { Password password = Iterables.getOnlyElement(from.getOperatingSystem().getPasswords()); builder.credentials(LoginCredentials.builder().identity(password.getUsername()).credential(password.getPassword()).build()); } if (from.getTagReferences() != null && !from.getTagReferences().isEmpty()) { List<String> tags = Lists.newArrayList(); for (TagReference tagReference : from.getTagReferences()) { if (tagReference != null) { tags.add(tagReference.getTag().getName()); } } builder.tags(tags); } return builder.build(); }