Fix NPE in PRED__load_commit_labels_1

If a change query uses reviewer information and loads the approvals
map, but there are no approvals for a given patch set available,
the collection came out null, which cannot be iterated. Make it
always be an empty list.

Change-Id: I5fd156a854099c5d4ce3c5c0c494b5498c4ed252
This commit is contained in:
Shawn O. Pearce
2012-05-03 15:31:41 -07:00
parent ece1a2ac34
commit 67caab5f74

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSet.Id;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.TrackingId;
@@ -221,7 +222,12 @@ public class ChangeData {
if (c == null) {
currentApprovals = Collections.emptyList();
} else if (approvals != null) {
currentApprovals = approvalsMap(db).get(c.currentPatchSetId());
Map<Id, Collection<PatchSetApproval>> map = approvalsMap(db);
currentApprovals = map.get(c.currentPatchSetId());
if (currentApprovals == null) {
currentApprovals = Collections.emptyList();
map.put(c.currentPatchSetId(), currentApprovals);
}
} else {
currentApprovals = db.get().patchSetApprovals()
.byPatchSet(c.currentPatchSetId()).toList();