Browse Source

fixes JASSIST-256, adding an annotation to a class doesn't work on reflection

tags/rel_3_21_0-java9-ea
chibash 8 years ago
parent
commit
1a33243aac

+ 1
- 1
Readme.html View File

@@ -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>


+ 1
- 1
src/main/javassist/bytecode/annotation/Annotation.java View File

@@ -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)

+ 1
- 1
src/main/javassist/bytecode/annotation/ArrayMemberValue.java View File

@@ -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);

+ 26
- 0
src/test/javassist/JvstTest5.java View File

@@ -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);
}
}

+ 9
- 0
src/test/test5/Entity.java View File

@@ -0,0 +1,9 @@
package test5;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Entity {
int[] value();
}

Loading…
Cancel
Save