diff options
author | chibash <chiba@javassist.org> | 2016-02-12 01:56:34 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2016-02-12 01:56:34 +0900 |
commit | 1a33243aac567886ee4eed52b53862f3a7ca7db7 (patch) | |
tree | fdb28a8009d863e850c188c2f3c430a0f099acab | |
parent | fee5e033b303efce0cb6d9268b5361d5e1eb1974 (diff) | |
download | javassist-1a33243aac567886ee4eed52b53862f3a7ca7db7.tar.gz javassist-1a33243aac567886ee4eed52b53862f3a7ca7db7.zip |
fixes JASSIST-256, adding an annotation to a class doesn't work on reflection
-rw-r--r-- | Readme.html | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/annotation/Annotation.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/annotation/ArrayMemberValue.java | 2 | ||||
-rw-r--r-- | src/test/javassist/JvstTest5.java | 26 | ||||
-rw-r--r-- | src/test/test5/Entity.java | 9 |
5 files changed, 38 insertions, 3 deletions
diff --git a/Readme.html b/Readme.html index b4d9314f..181b844e 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,7 @@ see javassist.Dump. <p>-version 3.21 <ul> -<li>JIRA JASSIST-244, 245, 248, 255 +<li>JIRA JASSIST-244, 245, 248, 255, 256, 259. </ul> </p> diff --git a/src/main/javassist/bytecode/annotation/Annotation.java b/src/main/javassist/bytecode/annotation/Annotation.java index 851d3f9c..831960e3 100644 --- a/src/main/javassist/bytecode/annotation/Annotation.java +++ b/src/main/javassist/bytecode/annotation/Annotation.java @@ -78,7 +78,7 @@ public class Annotation { * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * - * @param typeName the name of the annotation interface type. + * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) diff --git a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java index 58b09b38..389bdf90 100644 --- a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java @@ -130,7 +130,7 @@ public class ArrayMemberValue extends MemberValue { * Writes the value. */ public void write(AnnotationsWriter writer) throws IOException { - int num = values.length; + int num = values == null ? 0 : values.length; writer.arrayValue(num); for (int i = 0; i < num; ++i) values[i].write(writer); diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 8e1ef8a7..773ab8b6 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -3,7 +3,9 @@ package javassist; import java.lang.annotation.Annotation; import java.lang.reflect.TypeVariable; +import javassist.bytecode.AnnotationsAttribute; import javassist.bytecode.ClassFile; +import javassist.bytecode.ConstPool; import javassist.bytecode.InnerClassesAttribute; public class JvstTest5 extends JvstTestRoot { @@ -142,4 +144,28 @@ public class JvstTest5 extends JvstTestRoot { for (CtMethod method : c.getDeclaredMethods()) method.insertAfter(code); } + + public void testJIRA256() throws Exception { + // CtClass ec = sloader.get("test5.Entity"); + + CtClass cc = sloader.makeClass("test5.JIRA256"); + ClassFile ccFile = cc.getClassFile(); + ConstPool constpool = ccFile.getConstPool(); + + AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); + javassist.bytecode.annotation.Annotation entityAnno + = new javassist.bytecode.annotation.Annotation("test5.Entity", constpool); + // = new javassist.bytecode.annotation.Annotation(constpool, ec); + + entityAnno.addMemberValue("value", new javassist.bytecode.annotation.ArrayMemberValue(constpool)); + attr.addAnnotation(entityAnno); + ccFile.addAttribute(attr); + + cc.writeFile(); + Object o = make(cc.getName()); + assertTrue(o.getClass().getName().equals("test5.JIRA256")); + + java.lang.annotation.Annotation[] annotations = o.getClass().getDeclaredAnnotations(); + assertEquals(1, annotations.length); + } } diff --git a/src/test/test5/Entity.java b/src/test/test5/Entity.java new file mode 100644 index 00000000..1060c848 --- /dev/null +++ b/src/test/test5/Entity.java @@ -0,0 +1,9 @@ +package test5; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Entity { + int[] value(); +} |