frjaeger220 / google-guice

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

Method anntation lost when interceptor used with class annotation. #101

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When an interceptor is defined as a class annotation, method annotations of
the class which is intercepted are lost.

See the attachments. In Test.java , it has 2 Module classes: one has an
interceptor definition, and another does not.
Run Test.java, you will see the result as the following.

#:true
#:false

The second result means method annotations are lost.

Original issue reported on code.google.com by hiro0...@gmail.com on 6 May 2007 at 4:34

Attachments:

GoogleCodeExporter commented 9 years ago
Let me know,does this behavior seem to be part of the specification?

Original comment by hiro0...@gmail.com on 19 May 2007 at 1:14

GoogleCodeExporter commented 9 years ago
This is not a problem of guice itself, but rather an issue of the underlying 
proxy
creation libary cglib:

When you are intercepting method calls to objects, guice uses cglib to create a 
proxy
for these objects. Cglib again subclasses the object's type and overrides all 
non
final methods. So when you are calling object.getClass.getMethod() you are 
actually
getting the method of the dynamically created subtype. As far as I have 
followed the
cglib mailing list (http://osdir.com/ml/java.cglib.devel/2006-07/msg00006.html) 
no
annotations will be copy from your concrete type to the created subtype for 
backward
compability reasons (at least for cglib versions 2.x). Only type level 
annotations
can be accessed from the subtype, if the annotation type is annotated with
@java.lang.annotation.Inherited

Simple workaround would look like calling
object.getClass.getSuperclass().getMethod(), which is indead dirty and 
expensive.

Original comment by sven.lin...@gmail.com on 2 Jun 2008 at 9:57

GoogleCodeExporter commented 9 years ago
This was reported 2x, and issue 201 has more commentary. Closing as duplicate.

Original comment by limpbizkit on 8 Jun 2008 at 11:28