From eb2f987ddbca9202111137d33c367b8622f66b23 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 6 Mar 2018 15:54:13 +0900 Subject: [PATCH] BatchProgramModule: Don't bind event classes to null Instead, bind them to the DISABLED instance. Change-Id: I599caac02ae98800fba641c1e4f6088a9c894c48 --- .../gerrit/pgm/util/BatchProgramModule.java | 4 ++-- .../extensions/events/RevisionCreated.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/BatchProgramModule.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/BatchProgramModule.java index 05adf484bf..f17b3ed226 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/BatchProgramModule.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/BatchProgramModule.java @@ -168,8 +168,8 @@ public class BatchProgramModule extends FactoryModule { bind(ChangeJson.Factory.class).toProvider(Providers.of(null)); bind(EventUtil.class).toProvider(Providers.of(null)); - bind(GitReferenceUpdated.class).toProvider(Providers.of(null)); - bind(RevisionCreated.class).toProvider(Providers.of(null)); + bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED); + bind(RevisionCreated.class).toInstance(RevisionCreated.DISABLED); bind(AccountVisibility.class).toProvider(AccountVisibilityProvider.class).in(SINGLETON); } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/extensions/events/RevisionCreated.java b/gerrit-server/src/main/java/com/google/gerrit/server/extensions/events/RevisionCreated.java index 6f171e3988..20d0bf4e27 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/extensions/events/RevisionCreated.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/extensions/events/RevisionCreated.java @@ -37,6 +37,17 @@ import org.slf4j.LoggerFactory; public class RevisionCreated { private static final Logger log = LoggerFactory.getLogger(RevisionCreated.class); + public static final RevisionCreated DISABLED = + new RevisionCreated() { + @Override + public void fire( + Change change, + PatchSet patchSet, + Account uploader, + Timestamp when, + NotifyHandling notify) {} + }; + private final DynamicSet listeners; private final EventUtil util; @@ -46,6 +57,11 @@ public class RevisionCreated { this.util = util; } + private RevisionCreated() { + this.listeners = null; + this.util = null; + } + public void fire( Change change, PatchSet patchSet, Account uploader, Timestamp when, NotifyHandling notify) { if (!listeners.iterator().hasNext()) {