Labels: Fix NPE on merged change with no approvals

The Labels widget includes a list of votable label for each reviewer on
the change. Prior to I3a40f9d9, the list of reviewers was computed from
the labels list in the ChangeInfo. ReceiveCommits#markChangeMergedByPush
closes the change but does not stamp any labels at submit time, the
result being an empty label list, which in turn means an empty
reviewer list on a change that was marked merge by push. (That is not
optimal, but is not the problem we're solving here.)

After I3a40f9d9, the reviewer list is computed differently, so we may
have a non-empty reviewer list even though the label list is empty.
The empty label list is also used to build a map of account ID -> set
of votable labels. Since the label list is empty, that map is now
empty, so the VotableInfo returned from looking up a reviewer in that
map is null.

Check for null, avoiding an NPE in the client.

Change-Id: I511d4e6505ba8948bac52660b34ddfa2ca668947
This commit is contained in:
Dave Borowitz 2016-02-05 18:12:29 -05:00
parent f7ba00013d
commit f55bd4feac

View File

@ -279,17 +279,21 @@ class Labels extends Grid {
String votableCategories = "";
if (votable != null) {
Set<String> s = votable.get(ai._accountId()).votableLabels();
if (!s.isEmpty()) {
StringBuilder sb = new StringBuilder(Util.C.votable());
sb.append(" ");
for (Iterator<String> it = s.iterator(); it.hasNext();) {
sb.append(it.next());
if (it.hasNext()) {
sb.append(", ");
VotableInfo vi = votable.get(ai._accountId());
if (vi != null) {
Set<String> s = vi.votableLabels();
if (!s.isEmpty()) {
StringBuilder sb = new StringBuilder(Util.C.votable());
sb.append(" ");
for (Iterator<String> it = vi.votableLabels().iterator();
it.hasNext();) {
sb.append(it.next());
if (it.hasNext()) {
sb.append(", ");
}
}
votableCategories = sb.toString();
}
votableCategories = sb.toString();
}
}
html.openSpan()