From ec492eda872a8b3adad5c16b99552d30cea27eab Mon Sep 17 00:00:00 2001 From: Alice Kober-Sotzek Date: Thu, 9 Nov 2017 15:15:33 +0100 Subject: [PATCH] Correct RefUpdateUtil to work for an empty BatchRefUpdate RefUpdateUtil#checkResults should not throw a LockFailureException if the BatchRefUpdate doesn't contain any commands. Instead, it should silently do nothing as nothing was executed. Change-Id: Ie8257f8f9eb487f1242cacf004e05357e3fb6317 --- java/com/google/gerrit/server/update/RefUpdateUtil.java | 4 ++++ .../com/google/gerrit/server/update/RefUpdateUtilTest.java | 1 + 2 files changed, 5 insertions(+) diff --git a/java/com/google/gerrit/server/update/RefUpdateUtil.java b/java/com/google/gerrit/server/update/RefUpdateUtil.java index 86b4eef7c9..17c7812811 100644 --- a/java/com/google/gerrit/server/update/RefUpdateUtil.java +++ b/java/com/google/gerrit/server/update/RefUpdateUtil.java @@ -57,6 +57,10 @@ public class RefUpdateUtil { */ @VisibleForTesting static void checkResults(BatchRefUpdate bru) throws IOException { + if (bru.getCommands().isEmpty()) { + return; + } + int lockFailure = 0; int aborted = 0; int failure = 0; diff --git a/javatests/com/google/gerrit/server/update/RefUpdateUtilTest.java b/javatests/com/google/gerrit/server/update/RefUpdateUtilTest.java index 286827a056..fc8696aed4 100644 --- a/javatests/com/google/gerrit/server/update/RefUpdateUtilTest.java +++ b/javatests/com/google/gerrit/server/update/RefUpdateUtilTest.java @@ -53,6 +53,7 @@ public class RefUpdateUtilTest { @Test public void checkBatchRefUpdateResults() throws Exception { + checkResults(); checkResults(OK); checkResults(OK, OK);