[jboss-jira] [JBoss JIRA] (JASSIST-167) GenericSignatureFormatError when calling Field.getDeclaredAnnotations() on javassist field/annotation

Jeffrey Selk (JIRA) jira-events at lists.jboss.org
Mon May 14 10:20:19 EDT 2012


    [ https://issues.jboss.org/browse/JASSIST-167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12692680#comment-12692680 ] 

Jeffrey Selk commented on JASSIST-167:
--------------------------------------

I chose to use Retention and RentionPolicy because they were built-in java types but since it doesn't apply to Fields this was a bad example. Here's a better one using an Enum I define:

{code:title=MyUnit.java|borderStyle=solid}
// ENUM DEFINITION
package com.mytestcase
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
public @interface MyUnit {
    TimeUnit unit();
}
{code}

{code:title=MyTest.java|borderStyle=solid}
// JAVA ASSIST CODE
try {
            ClassPool pool = ClassPool.getDefault();
            CtClass bean = pool.makeClass("com.mytestcase.test.TestClass");
            String fieldCode = "private java.lang.String myString;";
            CtField field = CtField.make(fieldCode, bean);
            bean.addField(field);
            ConstPool constPool = field.getFieldInfo().getConstPool();
            AnnotationsAttribute annoAttr = new AnnotationsAttribute(constPool,
                    AnnotationsAttribute.visibleTag);
            javassist.bytecode.annotation.Annotation annot = new javassist.bytecode.annotation.Annotation(
                    com.mytestcase.MyUnit.class.getName(), constPool);
            EnumMemberValue e = new EnumMemberValue(constPool);
            e.setType(java.util.concurrent.TimeUnit.class.toString());
            e.setValue("DAYS");
            annot.addMemberValue("unit", e);
            field.getFieldInfo().addAttribute(annoAttr);
            annoAttr.addAnnotation(annot);
            Class<?> builtClass = bean.toClass();
            builtClass.getDeclaredFields()[0].getDeclaredAnnotations(); // throws
                                                                        // Exception
        } catch (CannotCompileException e) {
            e.printStackTrace();
        }
{code}
                
> GenericSignatureFormatError when calling Field.getDeclaredAnnotations() on javassist field/annotation
> -----------------------------------------------------------------------------------------------------
>
>                 Key: JASSIST-167
>                 URL: https://issues.jboss.org/browse/JASSIST-167
>             Project: Javassist
>          Issue Type: Bug
>    Affects Versions: 3.12.0.GA
>         Environment: CentOS release 6.2 x64
> Linux tucker 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux
> java version "1.6.0_31"
> Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
> Java HotSpot(TM) Server VM (build 20.6-b01, mixed mode)
>            Reporter: Jeffrey Selk
>            Assignee: Shigeru Chiba
>
> Using javassist to create a Field with an Annotation on it, and the Annotation contains a member that is an Enumeration, after the class is created a GenericSignatureFormatError is thrown when trying to introspect the Field.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list