OutgoingEmail#getNameEmailFor: Protect against null accountId
If the accountId is null, it results in a NullPointerException when attempting to get the account from the account cache: at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:782) at com.google.common.cache.LocalCache.get(LocalCache.java:4146) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4151) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5140) at com.google.gerrit.server.account.AccountCacheImpl.get(AccountCacheImpl.java:85) Check for null, and return the name and email address of the server identity, consistently with what #getNameFor does when the accountId is null. Update the Javadoc accordingly. Also update the Javadoc of #getNameFor to make it consistent. Change-Id: I8145ca79d2122616247b013f83ded50db1f30f62
This commit is contained in:
@@ -341,7 +341,12 @@ public abstract class OutgoingEmail {
|
||||
}
|
||||
}
|
||||
|
||||
/** Lookup a human readable name for an account, usually the "full name". */
|
||||
/**
|
||||
* Gets the human readable name for an account, usually the "full name".
|
||||
*
|
||||
* @param accountId user to fetch.
|
||||
* @return name of the account, or the server identity name if null.
|
||||
*/
|
||||
protected String getNameFor(final Account.Id accountId) {
|
||||
if (accountId == null) {
|
||||
return args.gerritPersonIdent.getName();
|
||||
@@ -351,13 +356,17 @@ public abstract class OutgoingEmail {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the human readable name and email for an account; if neither are available, returns the
|
||||
* Anonymous Coward name.
|
||||
* Gets the human readable name and email for an account.
|
||||
*
|
||||
* @param accountId user to fetch.
|
||||
* @return name/email of account, or Anonymous Coward if unset.
|
||||
* @return name/email of account; Anonymous Coward if unset or the server identity if null.
|
||||
*/
|
||||
public String getNameEmailFor(Account.Id accountId) {
|
||||
if (accountId == null) {
|
||||
return String.format(
|
||||
"%s <%s>", args.gerritPersonIdent.getName(), args.gerritPersonIdent.getEmailAddress());
|
||||
}
|
||||
|
||||
return args.accountCache.get(accountId).getAccount().getNameEmail(args.anonymousCowardName);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user