From 917fa77ca1d23825b46cb5686f6b1a903c9550d3 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 27 Jan 2016 11:00:18 +0100 Subject: [PATCH] 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 --- .../java/com/google/gerrit/server/ChangeMessagesUtil.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeMessagesUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeMessagesUtil.java index 94973f2833..07d4326ad0 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeMessagesUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeMessagesUtil.java @@ -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)); }