Adapt to changes in Gerrit API AccountCache#getByUsername now returns Optional<AccountState> insteadof a nullable AccountState. Change-Id: I9d791b79a8e8fb9e3ef06610c2a469c6a55dbec1 Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/singleusergroup/SingleUserGroup.java b/src/main/java/com/googlesource/gerrit/plugins/singleusergroup/SingleUserGroup.java index 6138171..c2869b2 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/singleusergroup/SingleUserGroup.java +++ b/src/main/java/com/googlesource/gerrit/plugins/singleusergroup/SingleUserGroup.java
@@ -45,6 +45,7 @@ import com.google.inject.Singleton; import java.util.Collection; import java.util.Collections; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,17 +104,17 @@ @Override public GroupDescription.Basic get(AccountGroup.UUID uuid) { String ident = username(uuid); - AccountState state; + Optional<AccountState> state; if (ident.matches(ACCOUNT_ID_PATTERN)) { - state = accountCache.get(new Account.Id(Integer.parseInt(ident))); + state = Optional.of(accountCache.get(new Account.Id(Integer.parseInt(ident)))); } else if (ident.matches(Account.USER_NAME_PATTERN)) { state = accountCache.getByUsername(ident); } else { return null; } - if (state != null) { - final String name = nameOf(uuid, state); - final String email = Strings.emptyToNull(state.getAccount().getPreferredEmail()); + if (state.isPresent()) { + String name = nameOf(uuid, state.get()); + String email = Strings.emptyToNull(state.get().getAccount().getPreferredEmail()); return new GroupDescription.Basic() { @Override public AccountGroup.UUID getGroupUUID() {