Avoid throwing exception due to deleted change When a refupdated event is fired due to the deletion of a change (ie. deleting a draft), the plugin attempts to post a stream event related to the change, but an unhelpful exception is thrown because the change no longer exists. Replace exception with a null check. Change-Id: I7819d3b249c456f9d2749b808a9e67fd4759e3e8
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java index bc503ac..fd4cebf 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
@@ -179,7 +179,10 @@ try { ReviewDb db = schema.open(); try { - hooks.postEvent(retrieveChange(ref, db), event, db); + Change change = retrieveChange(ref, db); + if (change != null) { + hooks.postEvent(change, event, db); + } } finally { db.close(); } @@ -196,9 +199,6 @@ throws OrmException, NoSuchChangeException { PatchSet.Id id = PatchSet.Id.fromRef(ref); Change change = db.changes().get(id.getParentKey()); - if (change == null) { - throw new NoSuchChangeException(id.getParentKey()); - } return change; } }