Today I have found an introspection problem within the Javassist library, I'm not sure is a problem of the library or of the bytecode manipulation. I found the problem while working around WhiteCat, that injects Java annotation into ordinary classes at run-time. Of course the injection works fine, but it is like the annotation is no more visible in an "ordinary" way. In fact, doing introspection against a manipulated class, I found that the annotations are there, but with a class name like $Proxy
. Why is this problematic? Simply because it does not allow for a class-to-class comparison when working with annotations, and more important it does not allow introspection against the annotation itself (e.g., to get the annotations of an annotation).
The solution in order to do regular introspection is the following:
- get the annotation and its toString() value;
- manipulate the string value in order to get the annotation fully qualified name;
- load the annotation class from its name thru reflection;
- work on the obtained class.
Not really clean, but good enough for WhiteCat to work.