]
Shigeru Chiba commented on JASSIST-256:
---------------------------------------
Yes, but the version including this fixing has not been released yet.
Javassist - add annotation to class doesn't work on reflections
---------------------------------------------------------------
Key: JASSIST-256
URL:
https://issues.jboss.org/browse/JASSIST-256
Project: Javassist
Issue Type: Bug
Affects Versions: 3.20.0-GA
Environment: JDK1.7, IDEA
Reporter: Rui C.
Assignee: Shigeru Chiba
Priority: Minor
Fix For: 3.21.0-GA
{code:java}
ClassPool pool = ClassPool.getDefault();
CtClass superclass = pool.getCtClass(AbstractEntity.class.getName());
CtClass cc = pool.makeClass("com.rapid.develop.entity.Ponit", superclass);
ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
AnnotationsAttribute.visibleTag);
Annotation entityAnno = new Annotation("Entity", constpool);
Annotation tableAnno = new Annotation("Table", constpool);
tableAnno.addMemberValue("name", new StringMemberValue("test",
ccFile.getConstPool()));
attr.addAnnotation(entityAnno);
attr.addAnnotation(tableAnno);
ccFile.addAttribute(attr);
Class clazz = cc.toClass();
Object o = clazz.newInstance();
assertTrue(o.getClass().getName().equals("com.rapid.develop.entity.Ponit"));
// annotations length = zero
java.lang.annotation.Annotation[] annotations = clazz.getDeclaredAnnotations();
assertEquals(2, annotations.length);
{code}
I used javassist to add annotation for class, I saw these annotations were added to class
file.
But I can't get them using java API clazz.getDeclaredAnnotations() and
clazz.getAnnotations()