From e3d23d64eb9c05305e1aa7959632da1ae2f4b98d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 17 May 2012 09:19:51 -0700 Subject: [PATCH] Don't bind non-annotated types into DynamicSet, DynamicMap When attaching implementations into a DynamicSet or DynamicMap, only connect ones bound with an annotation. This enables code to bind the interface twice, for example: class GroupModule extends AbstractModule { protected void configure() { DynamicSet.setOf(binder(), GroupBackend.class); DynamicSet.bind(binder(), GroupBackend.class).to(LdapBackend.class); bind(GroupBackend.class).to(UniversalBackend.class); } } class UniversalBackend implements GroupBackend { @Inject UniversalBackend(DynamicSet all) { } } Without this no-annotation filter, the universal backend would be added to its own DynamicSet and create a possible infinite recursion scenario. Change-Id: Ifcf08cc577acc7fc31d4eef0465d485e8878f4fc --- .../registration/PrivateInternals_DynamicTypes.java | 8 ++++++-- .../gerrit/server/plugins/PluginGuiceEnvironment.java | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicTypes.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicTypes.java index de1cd68262..66dd45d657 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicTypes.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicTypes.java @@ -79,7 +79,9 @@ public class PrivateInternals_DynamicTypes { DynamicSet set = (DynamicSet) e.getValue(); for (Binding b : bindings(src, type)) { - handles.add(set.add(b.getKey(), b.getProvider())); + if (b.getKey().getAnnotation() != null) { + handles.add(set.add(b.getKey(), b.getProvider())); + } } } } catch (RuntimeException e) { @@ -111,7 +113,9 @@ public class PrivateInternals_DynamicTypes { (PrivateInternals_DynamicMapImpl) e.getValue(); for (Binding b : bindings(src, type)) { - handles.add(set.put(groupName, b.getKey(), b.getProvider())); + if (b.getKey().getAnnotation() != null) { + handles.add(set.put(groupName, b.getKey(), b.getProvider())); + } } } } catch (RuntimeException e) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java index e541b103c3..3aa259edf2 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java @@ -258,6 +258,9 @@ public class PluginGuiceEnvironment { @SuppressWarnings("unchecked") Binding b = (Binding) binding; Key key = b.getKey(); + if (key.getAnnotation() == null) { + continue; + } @SuppressWarnings("unchecked") ReloadableRegistrationHandle h = @@ -323,6 +326,9 @@ public class PluginGuiceEnvironment { @SuppressWarnings("unchecked") Binding b = (Binding) binding; Key key = b.getKey(); + if (key.getAnnotation() == null) { + continue; + } @SuppressWarnings("unchecked") ReloadableRegistrationHandle h1 =