ChangeHookApiListener: Prevent NPE when event includes null account

In some events, for example ref-updated, the account member can be
left unset (i.e. null), which causes NPE in getAccount which was
dereferencing it without null-check.

Change-Id: Ic93af1f3fdd0e5aa67583d3ecea22a52e38d15c3
This commit is contained in:
David Pursehouse
2016-06-23 09:30:56 +09:00
parent 1265695878
commit 5c3c4c8bb3

View File

@@ -47,6 +47,7 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gwtorm.server.OrmException;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.events.CommitReceivedEvent;
import com.google.gerrit.server.git.validators.CommitValidationListener;
import com.google.gerrit.server.git.validators.CommitValidationMessage;
@@ -354,7 +355,13 @@ public class ChangeHookApiListener implements
}
private Account getAccount(AccountInfo info) {
return accounts.get(new Account.Id(info._accountId)).getAccount();
if (info != null) {
AccountState account = accounts.get(new Account.Id(info._accountId));
if (account != null) {
return account.getAccount();
}
}
return null;
}
private static Map<String, Short> convertApprovalsMap(