AccountValidator: Handle missing user branches

AccountConfig returns null from getAccount() if the user branch is
missing. Handle the null case in AccountValidator although this should
never happen (since all callers of AccountValidator get the account ID
from an existing user branch).

Change-Id: If781c8e15c5fa90a0f2d2bed3443c0285cc398f0
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-12-07 14:21:18 +01:00
parent db92484e5e
commit 897267d3da
2 changed files with 8 additions and 1 deletions

View File

@@ -97,9 +97,11 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
/**
* Get the loaded account.
*
* @return loaded account.
* @return the loaded account, {@code null} if load didn't find the account because it doesn't
* exist
* @throws IllegalStateException if the account was not loaded yet
*/
@Nullable
public Account getAccount() {
checkLoaded();
return account;

View File

@@ -62,6 +62,10 @@ public class AccountValidator {
newId.name(), AccountConfig.ACCOUNT_CONFIG, accountId.get(), e.getMessage()));
}
if (newAccount == null) {
return ImmutableList.of(String.format("account '%s' does not exist", accountId.get()));
}
List<String> messages = new ArrayList<>();
if (accountId.equals(self.get().getAccountId()) && !newAccount.isActive()) {
messages.add("cannot deactivate own account");
@@ -81,6 +85,7 @@ public class AccountValidator {
return ImmutableList.copyOf(messages);
}
@Nullable
private Account loadAccount(Account.Id accountId, RevWalk rw, ObjectId commit)
throws IOException, ConfigInvalidException {
rw.reset();