Fix ChangeRebuilderImpl with null account IDs
The Event comparator had a NPE when used with a null account ID, which is otherwise supported. This only shows up after comparing a few more fields, which may be why it hasn't shown up yet. (Or maybe we didn't have any test cases at all with null IDs.) Change-Id: I3723b0c9a90eac7ddd9b283d1e332ef92667c63b
This commit is contained in:
@@ -27,11 +27,14 @@ import com.google.gerrit.extensions.api.changes.DraftInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||
import com.google.gerrit.server.change.Rebuild;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
@@ -154,6 +157,20 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
|
||||
checker.rebuildAndCheckChanges(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullAccountId() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
PatchSet.Id psId = r.getPatchSetId();
|
||||
Change.Id id = psId.getParentKey();
|
||||
|
||||
// Events need to be otherwise identical for the account ID to be compared.
|
||||
ChangeMessage msg1 =
|
||||
insertMessage(psId, user.getId(), TimeUtil.nowTs(), "message 1");
|
||||
insertMessage(psId, null, msg1.getWrittenOn(), "message 2");
|
||||
|
||||
checker.rebuildAndCheckChanges(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noWriteToNewRef() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
@@ -387,6 +404,24 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
|
||||
}
|
||||
}
|
||||
|
||||
private ChangeMessage insertMessage(PatchSet.Id psId, Account.Id author,
|
||||
Timestamp ts, String message) throws Exception {
|
||||
Change.Id id = psId.getParentKey();
|
||||
ChangeMessage msg = new ChangeMessage(
|
||||
new ChangeMessage.Key(id, ChangeUtil.messageUUID(db)),
|
||||
author, ts, psId);
|
||||
msg.setMessage(message);
|
||||
db.changeMessages().insert(Collections.singleton(msg));
|
||||
|
||||
Change c = db.changes().get(id);
|
||||
if (ts.compareTo(c.getLastUpdatedOn()) > 0) {
|
||||
c.setLastUpdatedOn(ts);
|
||||
db.changes().update(Collections.singleton(c));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
private ReviewDb unwrapDb() {
|
||||
ReviewDb db = dbProvider.get();
|
||||
if (db instanceof DisabledChangesReviewDbWrapper) {
|
||||
|
||||
Reference in New Issue
Block a user