Comment #3 on issue 252 by sberlin: Guice-AOP invok "synthetic" method
http://code.google.com/p/google-guice/issues/detail?id=252
Below is a smaller JUnit-style testcase that reproduces the problem:
public void testDoesNotInterceptTwiceOnSyntheticMethods() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Store.class).to(ConeyIslandStore.class);
bindInterceptor(Matchers.any(), new AbstractMatcher<Method>() {
public boolean matches(Method t) {
System.out.println("synthetic: " + t.isSynthetic() + ", t: " +
t);
return true;
}
}, new CountingInterceptor());
}
});
Store store = injector.getInstance(Store.class);
store.cookDog();
assertEquals(1, count.get());
}
interface HotDog {}
static class NathansDog implements HotDog {}
interface Store {
HotDog cookDog();
}
static class ConeyIslandStore implements Store {
public NathansDog cookDog() {
return null;
}
}
(where CountingInterceptor is an interceptor that increments a 'count'
variable).
To be honest, I'm not certain we should fix this. Yes, it can intercept
twice if your matcher is broad... but if we rule out all synthetic methods,
then it may prevent your matcher from matching entirely, because it may
only have wanted to match on the return value from the synthetic method.
Will think on this a bit more...
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.