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,9 +79,11 @@ public class PrivateInternals_DynamicTypes {
|
|||||||
DynamicSet<Object> set = (DynamicSet<Object>) e.getValue();
|
DynamicSet<Object> set = (DynamicSet<Object>) e.getValue();
|
||||||
|
|
||||||
for (Binding<Object> b : bindings(src, type)) {
|
for (Binding<Object> b : bindings(src, type)) {
|
||||||
|
if (b.getKey().getAnnotation() != null) {
|
||||||
handles.add(set.add(b.getKey(), b.getProvider()));
|
handles.add(set.add(b.getKey(), b.getProvider()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
remove(handles);
|
remove(handles);
|
||||||
throw e;
|
throw e;
|
||||||
@@ -111,9 +113,11 @@ public class PrivateInternals_DynamicTypes {
|
|||||||
(PrivateInternals_DynamicMapImpl<Object>) e.getValue();
|
(PrivateInternals_DynamicMapImpl<Object>) e.getValue();
|
||||||
|
|
||||||
for (Binding<Object> b : bindings(src, type)) {
|
for (Binding<Object> b : bindings(src, type)) {
|
||||||
|
if (b.getKey().getAnnotation() != null) {
|
||||||
handles.add(set.put(groupName, b.getKey(), b.getProvider()));
|
handles.add(set.put(groupName, b.getKey(), b.getProvider()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
remove(handles);
|
remove(handles);
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -258,6 +258,9 @@ public class PluginGuiceEnvironment {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Binding<Object> b = (Binding<Object>) binding;
|
Binding<Object> b = (Binding<Object>) binding;
|
||||||
Key<Object> key = b.getKey();
|
Key<Object> key = b.getKey();
|
||||||
|
if (key.getAnnotation() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ReloadableRegistrationHandle<Object> h =
|
ReloadableRegistrationHandle<Object> h =
|
||||||
@@ -323,6 +326,9 @@ public class PluginGuiceEnvironment {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Binding<Object> b = (Binding<Object>) binding;
|
Binding<Object> b = (Binding<Object>) binding;
|
||||||
Key<Object> key = b.getKey();
|
Key<Object> key = b.getKey();
|
||||||
|
if (key.getAnnotation() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ReloadableRegistrationHandle<Object> h1 =
|
ReloadableRegistrationHandle<Object> h1 =
|
||||||
|
|||||||
Reference in New Issue
Block a user