[jboss-dev-forums] [JBoss Microcontainer Development] - ClassInfo::getAnnotations bug
alesj
do-not-reply at jboss.com
Thu Oct 22 11:24:31 EDT 2009
While doing annotation scanning on top of Reflect,
I stumbled upon what seems to me an invalid impl of how we get annotations of the class.
ClassInfoImpl uses InheritableAnnotationHolder who's getAnnotations returns all annotations in the class hierarchy.
This way we cannot just get the annotations declared on the class,
making it look like all annotations are marked as @Inherited.
In my case AnnotationRepository was picking up class which wasn't annotated, but its super class was.
Flavia and me fixed this by introducing a notion of getDeclaredAnnotations on InheritableAnnotationHolder,
which is then used by ClassInfoImpl.
But this leads to another problem. :-(
While testing Deployers, ManagedObjectClassLoadingParserUnitTestCase was failing for me.
This is due to the fact that Managed is trying to create ManagedObject
while looking for @ManagementObject on the attachment's class.
In this case the attachment is of ClassLoadingMetaData10,
where @ManagementObject is on its superclass, ClassLoadingMetaData.
With the current Reflection fix AbstractManagedObjectFactory::getAnnotation only checks top class,
not the whole hierarchy as before.
The fix for Managed could be:
* make @ManagementObject @Inherited
* check the whole hierarchy
But this seems more generic problem as just Managed.
I guess only change to Reflect 2.2.x will expose them all.
Or, is there actually a reason behind why we returned all annotations?
If there is one, how did we expect to just get class's annotations?
e.g. clazz::getAnnotations - clazz.getSuperclass.getAnnotations
I still prefer the way JDK does it. :-)
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4261751#4261751
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4261751
More information about the jboss-dev-forums
mailing list