NoteDb: Check change message author matches update author

At the moment the author of a change message is ignored when the
change message is written to notedb and the change message is recorded
on behalf of the user for which the ChangeUpdate was instantiated.
These users should be the same, but add a check to verify this so that
the change message data in the database and in notedb cannot become
inconsistent.

Change-Id: I6132a2dda18b5cfb27563211ebf9fc70dbef403d
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2016-01-27 11:00:18 +01:00 committed by Dave Borowitz
parent 6293c55c33
commit 917fa77ca1

View File

@ -14,6 +14,8 @@
package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.annotations.VisibleForTesting;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchSet;
@ -27,6 +29,7 @@ import com.google.inject.Singleton;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Utility functions to manipulate ChangeMessages.
@ -68,6 +71,11 @@ public class ChangeMessagesUtil {
public void addChangeMessage(ReviewDb db, ChangeUpdate update,
ChangeMessage changeMessage) throws OrmException {
checkState(
Objects.equals(changeMessage.getAuthor(),
update.getUser().getAccountId()),
"cannot store change message of %s in update of %s",
changeMessage.getAuthor(), update.getUser().getAccountId());
update.setChangeMessage(changeMessage.getMessage());
db.changeMessages().insert(Collections.singleton(changeMessage));
}