diff options
Diffstat (limited to 'java/com/google/gerrit/server/mail/send/OutgoingEmail.java')
-rw-r--r-- | java/com/google/gerrit/server/mail/send/OutgoingEmail.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/java/com/google/gerrit/server/mail/send/OutgoingEmail.java b/java/com/google/gerrit/server/mail/send/OutgoingEmail.java index 3bb710bb02..97035f23b4 100644 --- a/java/com/google/gerrit/server/mail/send/OutgoingEmail.java +++ b/java/com/google/gerrit/server/mail/send/OutgoingEmail.java @@ -21,6 +21,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.collect.Sets; import com.google.common.flogger.FluentLogger; import com.google.gerrit.exceptions.EmailException; +import com.google.gerrit.common.Nullable; import com.google.gerrit.extensions.api.changes.RecipientType; import com.google.gerrit.extensions.client.GeneralPreferencesInfo; import com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailFormat; @@ -333,7 +334,7 @@ public abstract class OutgoingEmail { } /** Lookup a human readable name for an account, usually the "full name". */ - protected String getNameFor(Account.Id accountId) { + protected String getNameFor(@Nullable Account.Id accountId) { if (accountId == null) { return args.gerritPersonIdent.getName(); } @@ -359,7 +360,14 @@ public abstract class OutgoingEmail { * @param accountId user to fetch. * @return name/email of account, or Anonymous Coward if unset. */ - protected String getNameEmailFor(Account.Id accountId) { + protected String getNameEmailFor(@Nullable Account.Id accountId) { + if (accountId == null) { + return args.gerritPersonIdent.getName() + + " <" + + args.gerritPersonIdent.getEmailAddress() + + ">"; + } + Optional<Account> account = args.accountCache.get(accountId).map(AccountState::getAccount); if (account.isPresent()) { String name = account.get().getFullName(); @@ -380,9 +388,13 @@ public abstract class OutgoingEmail { * username. If no username is set, this function returns null. * * @param accountId user to fetch. - * @return name/email of account, username, or null if unset. + * @return name/email of account, username, or null if unset or the accountId is null. */ - protected String getUserNameEmailFor(Account.Id accountId) { + protected String getUserNameEmailFor(@Nullable Account.Id accountId) { + if (accountId == null) { + return null; + } + Optional<AccountState> accountState = args.accountCache.get(accountId); if (!accountState.isPresent()) { return null; |