Source:
<code>private Future<Optional<String>> sendEmail(EmailNotificationType emailNotificationType, Charge charge, GatewayAccountEntity gatewayAccountEntity, HashMap<String, String> personalisation) { boolean isEmailEnabled = ofNullable(gatewayAccountEntity.getEmailNotifications().get(emailNotificationType)) .map(EmailNotificationEntity::isEnabled) .orElse(false); if (!emailNotifyGloballyEnabled || !isEmailEnabled || gatewayAccountEntity.getEmailCollectionMode().equals(OFF) || gatewayAccountEntity.getEmailCollectionMode().equals(OPTIONAL) && ofNullable(charge.getEmail()).isEmpty()) { return CompletableFuture.completedFuture(Optional.empty()); } <START> if (charge.getEmail() == null || charge.getEmail().isEmpty()) { <END> logger.warn("Cannot send email for charge_external_id = because the charge does not have an email address", charge.getExternalId()); return CompletableFuture.completedFuture(Optional.empty()); } Stopwatch responseTimeStopwatch = Stopwatch.createStarted(); return executorService.submit(() -> { try { NotifyClientSettings notifyClientSettings = getNotifyClientSettings(emailNotificationType, gatewayAccountEntity); logger.info("Sending email, charge_external_id={}", emailNotificationType, charge.getExternalId()); SendEmailResponse response = notifyClientSettings.getClient() .sendEmail(notifyClientSettings.getTemplateId(), charge.getEmail(), personalisation, null); return Optional.of(response.getNotificationId().toString()); } catch (NotificationClientException e) { logger.error("Failed to send " + emailNotificationType + " email - charge_external_id=" + charge.getExternalId(), e); metricRegistry.counter("notify-operations.failures").inc(); return Optional.empty(); } finally { responseTimeStopwatch.stop(); metricRegistry.histogram("notify-operations.response_time").update(responseTimeStopwatch.elapsed(TimeUnit.MILLISECONDS)); } }); }</code><technical_language>empty null? want a check for empty if happen people can</technical_language>

Target:
private Future<Optional<String>> sendEmail(EmailNotificationType emailNotificationType, Charge charge, GatewayAccountEntity gatewayAccountEntity, HashMap<String, String> personalisation) { boolean isEmailEnabled = ofNullable(gatewayAccountEntity.getEmailNotifications().get(emailNotificationType)) .map(EmailNotificationEntity::isEnabled) .orElse(false); if (!emailNotifyGloballyEnabled || !isEmailEnabled || gatewayAccountEntity.getEmailCollectionMode().equals(OFF) || gatewayAccountEntity.getEmailCollectionMode().equals(OPTIONAL) && ofNullable(charge.getEmail()).isEmpty()) { return CompletableFuture.completedFuture(Optional.empty()); } if (charge.getEmail() == null) { logger.warn("Cannot send email for charge_external_id = because the charge does not have an email address", charge.getExternalId()); return CompletableFuture.completedFuture(Optional.empty()); } Stopwatch responseTimeStopwatch = Stopwatch.createStarted(); return executorService.submit(() -> { try { NotifyClientSettings notifyClientSettings = getNotifyClientSettings(emailNotificationType, gatewayAccountEntity); logger.info("Sending email, charge_external_id={}", emailNotificationType, charge.getExternalId()); SendEmailResponse response = notifyClientSettings.getClient() .sendEmail(notifyClientSettings.getTemplateId(), charge.getEmail(), personalisation, null); return Optional.of(response.getNotificationId().toString()); } catch (NotificationClientException e) { logger.error("Failed to send " + emailNotificationType + " email - charge_external_id=" + charge.getExternalId(), e); metricRegistry.counter("notify-operations.failures").inc(); return Optional.empty(); } finally { responseTimeStopwatch.stop(); metricRegistry.histogram("notify-operations.response_time").update(responseTimeStopwatch.elapsed(TimeUnit.MILLISECONDS)); } }); }