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<GroupBackend> 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
This commit is contained in:
@@ -79,7 +79,9 @@ public class PrivateInternals_DynamicTypes {
|
||||
DynamicSet<Object> set = (DynamicSet<Object>) e.getValue();
|
||||
|
||||
for (Binding<Object> 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<Object>) e.getValue();
|
||||
|
||||
for (Binding<Object> 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) {
|
||||
|
||||
Reference in New Issue
Block a user