@Provides methods in modules are bound through that method.  If there's a
problem, it'll be surfaced by finding/calling the wrong @Provides methods.

 sam


On Fri, Apr 11, 2014 at 4:53 AM, Jochen Wiedmann
<[email protected]>wrote:

>
> I have spotted what I believe to be a bug in the Guice source code, namely
> ProviderMethodsModule.getProviderMethods:
>
>  public List<ProviderMethod<?>> getProviderMethods(Binder binder) {
>     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)) {
>           result.add(createProviderMethod(binder, method));
>         }
>       }
>     }
>     return result;
>   }
>
> The bug is that using c.getDeclaredMethods() is a simplification, because
> it would miss the following case:
>
>   public class FooSuper {
>     @PostConstruct
>     public void start() {
>       // Whatever
>     }
>   }
>
>   public class FooSub {
>     public void start() {
>       super.start();
>     }
>   }
>
> Fact is, that FooSub.getDeclaredMethods() returns FooSub.start (a method
> without annotation), and not FooSuper.start (the annotated method).
>
> I can provide
>   a) a test case, that demonstrates the asserted behaviour of
> Class.getDeclaredMethods()
>   b) a replacement method, that avoids that problem by iterating over
> super classes and implemented interfaces.
>
> However, I can't provide a test case that exposes the problem by using
> Guice, because it is not clear to me, how to reach
> ProviderMethodsModule.getProviderMethods().
> For the same reason, I cannot judge, whether the problem is negligible, or
> not. However, I suspect that Class.getDeclaredMethods() might be used
> elsewhere.
>
> Any interest?
>
> Jochen
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "google-guice" 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" 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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to