AOP classes don't get the annotations of the superclass
See original GitHub issueFrom anthony.muller on May 30, 2008 05:41:03
@
ME :
I’m quite suprised… I annoted a method @
MyAnnotation, in order to
intercept calls of this method. My problem is when I instanciate an object
which has a such annotation using guice. when i search the annoted method
through reflection, and i call isAnnotationPresent(MyAnnotation.class),
this method returns false!
@
jesse@
swank.ca: Under the hood, Guice creates a subclass of TotoImpl
in order to perform method interception.
For the most part, this is completely transparent to the developer, but there’s a few consequences. getClass() doesn’t return TotoImpl.class. This constraints how your equals() method must be implemented.
I also expect Serializable won’t interoperate with method interception.
The workaround in this case is to use TotoImpl.class rather than toto.getClass() to introspect on your type.
_Original issue: http://code.google.com/p/google-guice/issues/detail?id=201_
Issue Analytics
- State:
- Created 9 years ago
- Comments:17
Top GitHub Comments
Yeah I’m also a little shocked that this has gone on for 6 years now… I’m trying to add AOP to intercept the methods in a Dropwizard service and this totally kills that idea.
I think I’ve fixed this issue by writing a custom method matcher - please see https://codingcraftsman.wordpress.com/2018/11/11/google-guice-aop-with-interface-annotations/ and feedback if it’s a solution for you.