To compute the related changes of a patch set we:
1. Get all the groups from the patch sets of the corresponding change.
2. Query for all changes in the project that have any of these groups.
The matched changes are then sorted by RelatedChangesSorter.
It is expected that the change for which the REST endpoint is invoked is
contained in the set of matched changes. Since we search by the change's
project and groups, it must always match.
However the index can be stale for that change in two ways:
1. The index knows the change but not yet the patch set for which the
REST endpoint is invoked.
2. The index does not yet know the change for which the REST endpoint is
invoked.
Case 1. was already handled by forcing a reload of the change when the
wanted patch set was not present in the ChangeData that was returned
from the index.
This change adds handling for case 2. If the change is missing in the
index result we now load its ChangeData from NoteDb and add it to the
result.
If the change is missing in the result then RelatedChangesSorter#sort
fails with a NullPointerException because it doesn't find a commit for
the given start patch set [1] (the commits are gathered from the given
change set which is missing the change for the start patch set).
[1]
java.lang.NullPointerException: commit b0f113907a693dbf911f5721afb5332647ed6990 of patch set 121,1 not found in {936be82cf638c033e1674c19b086bc0af8b07300=122,1, 2e5531ccee8872ddfb6595798416512f0fe6dec0=123,1}
at java.util.Objects.requireNonNull(Objects.java:290)
at com.google.gerrit.server.restapi.change.RelatedChangesSorter.sort(RelatedChangesSorter.java:80)
at com.google.gerrit.server.restapi.change.GetRelated.getRelated(GetRelated.java:103)
at com.google.gerrit.server.restapi.change.GetRelated.apply(GetRelated.java:76)
at com.google.gerrit.server.restapi.change.GetRelated.apply(GetRelated.java:52)
at com.google.gerrit.httpd.restapi.RestApiServlet.lambda$invokeRestReadViewWithRetry$3(RestApiServlet.java:741)
....
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I9a94d734aed5a84c8d9510f6fcc5baca4c3416e2