xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Interceptors are matched incorrectly when there are generics involved #640

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The attached project produces:

05/07/2011 10:42:43 com.google.inject.internal.ProxyFactory <init>
WARNING: Method [public BaseEntity Service1Impl.doThing()] is synthetic and is 
being intercepted by [MyModule$TransactionInterceptor@4f2b6c89]. This could 
indicate a bug.  The method may be intercepted twice, or may not be intercepted 
at all.
begin
begin
Service1Impl.doThing
end
end

While the correct should be:
begin
Service1Impl.doThing
end

Original issue reported on code.google.com by adrianosf on 5 Jul 2011 at 1:45

Attachments:

GoogleCodeExporter commented 9 years ago
You'll note that Guice is printing out a warning here, telling you that it can 
intercept the method twice.  Java actually produces to different methods here 
-- one is synthetic and delegates to the other -- in order for things to work 
under the covers.  So Guice is intercepting both.  It's unfortunately very 
difficult for Guice itself to do the right thing here, because it's difficult 
to figure out if you want to intercept just the generic signature, the base 
signature, or both.

You can force Guice to do the (most likely) right thing by adding a custom 
method matcher that returns false if the method is synthetic 
(Method.isSynthetic).  Something like new 
MyMatcher().and(Matchers.noSynthetics()).

Original comment by sberlin on 5 Jul 2011 at 2:13

GoogleCodeExporter commented 9 years ago
Thanks. That seems ok for me.

Original comment by adrianosf on 5 Jul 2011 at 2:43