Revision: 53a5936f5505
Author: Sam Berlin <[email protected]>
Date: Fri May 23 22:19:12 2014 UTC
Log: Ignore synthetic bridge methods during provider method lookup.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=67854418
http://code.google.com/p/google-guice/source/detail?r=53a5936f5505
Modified:
/core/src/com/google/inject/internal/ProviderMethodsModule.java
/core/test/com/google/inject/spi/ProviderMethodsTest.java
=======================================
--- /core/src/com/google/inject/internal/ProviderMethodsModule.java Sat May
10 14:34:16 2014 UTC
+++ /core/src/com/google/inject/internal/ProviderMethodsModule.java Fri May
23 22:19:12 2014 UTC
@@ -81,13 +81,25 @@
List<ProviderMethod<?>> result = Lists.newArrayList();
for (Class<?> c = delegate.getClass(); c != Object.class; c =
c.getSuperclass()) {
for (Method method : c.getDeclaredMethods()) {
- if (method.isAnnotationPresent(Provides.class)) {
+ if (isProvider(method)) {
result.add(createProviderMethod(binder, method));
}
}
}
return result;
}
+
+ /**
+ * Returns true if the method is a provider.
+ *
+ * Synthetic bridge methods are excluded. Starting with JDK 8, javac
copies annotations onto
+ * bridge methods (which always have erased signatures).
+ */
+ private static boolean isProvider(Method method) {
+ return !method.isBridge()
+ && !method.isSynthetic()
+ && method.isAnnotationPresent(Provides.class);
+ }
<T> ProviderMethod<T> createProviderMethod(Binder binder, final Method
method) {
binder = binder.withSource(method);
=======================================
--- /core/test/com/google/inject/spi/ProviderMethodsTest.java Sat May 10
14:34:16 2014 UTC
+++ /core/test/com/google/inject/spi/ProviderMethodsTest.java Fri May 23
22:19:12 2014 UTC
@@ -643,4 +643,25 @@
return ImmutableList.of("baselist");
}
}
+
+ interface ProviderInterface<T> {
+ T getT();
+ }
+
+ static class ModuleImpl extends AbstractModule implements
ProviderInterface<String> {
+ @Override protected void configure() {}
+ @Provides public String getT() {
+ return "string";
+ }
+ @Provides public Object getObject() {
+ return new Object();
+ }
+ /* javac will synthesize a bridge method for getT with the types
erased, equivalent to:
+ * @Provides public Object getT() { ... }
+ */
+ }
+
+ public void testIgnoreSyntheticBridgeMethods() {
+ Guice.createInjector(new ModuleImpl());
+ }
}
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/d/optout.