[jboss-jira] [JBoss JIRA] (JASSIST-256) Javassist - add annotation to class doesn't work on reflections
Shigeru Chiba (JIRA)
issues at jboss.org
Thu Feb 11 11:55:00 EST 2016
[ https://issues.jboss.org/browse/JASSIST-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Shigeru Chiba resolved JASSIST-256.
-----------------------------------
Fix Version/s: 3.21.0-GA
Resolution: Done
No, the problem is that "Entity" is not a fully-qualified class name.
{code:java}
Annotation entityAnno = new Annotation("Entity", constpool);
{code}
I've fixed a problem of ArrayMemberValue.
> 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()
>
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list