vipx / google-guice

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

Interceptor enhanced classes not participating in type listener #737

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using a type listener to register beans with JMX with the appropriate 
annotation.  And I'm using method interception to implement a "tracing" 
annotation turning method call tracing on/off.

Unfortunately they interoperate poorly.  Intercepted methods have their classes 
enhanced, but the type listener only sees the plain instances, not the 
enhanced.  So the type listener fails to register it with JMX.

(Unless, of course, I'm doing it wrong.)

Original issue reported on code.google.com by b.k.ox...@gmail.com on 13 Dec 2012 at 8:18

Attachments:

GoogleCodeExporter commented 9 years ago
Left out main() class pulling it all together.

Original comment by b.k.ox...@gmail.com on 13 Dec 2012 at 8:20

Attachments:

GoogleCodeExporter commented 9 years ago
Your matcher uses:

   return type.getRawType().isAnnotationPresent(MBean.class);

but because the AOP proxy class generated by CGLIB doesn't redeclare the class 
annotation (and the JEE MBean annotation is not declared as @Inherited) then 
this matcher won't match the enhanced instances.

To handle this you need to use something like:

   return type.getRawType().isAnnotationPresent(MBean.class) ||
       type.getRawType().getSuperclass().isAnnotationPresent(MBean.class);

Note that any generated AOP classes will have 'ByGuice' in their name, so you 
could always use this to decide whether to check the superclass or not. 
Alternatively you could always walk up the superclass hierarchy which would 
then work for other proxied classes from other frameworks.

Original comment by mccu...@gmail.com on 12 May 2013 at 9:16