Do not fail with NPE if change is not found

If a change ref is updated the plugin expects to find the
corresponding change in the database and fails with a
NullPointerException if the change cannot be found in the database.

Add a check for this case and do not fail with an NPE, but instead
ignore this ref update and write a warning into the log.

Unfortunately in a few cases Gerrit sends the ref-updated event for the
change ref before it creates the change in the database. This happens
whenever the project.config in refs/meta/config is updated, e.g. if
permissions of a project are changed and saved for review.

Change-Id: I10ca7603dc57a1aa9bc29ec396f2c9f988e9fc3d
Signed-off-by: Edwin Kempin <>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/
index c5360c8..5b39824 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/
@@ -98,6 +98,10 @@
           PatchSet.Id psId = PatchSet.Id.fromRef(u.getRefName());
           PatchSet ps = reviewDb.patchSets().get(psId);
           final Change change = reviewDb.changes().get(psId.getParentKey());
+          if (change == null) {
+            log.warn("No change found for " + u.getRefName());
+            continue;
+          }
           final RevCommit commit =