From: chiba Date: Wed, 7 Sep 2005 02:09:58 +0000 (+0000) Subject: fixed a bug found when an annotation includes an empty array. X-Git-Tag: rel_3_17_1_ga~419 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5292871f7db7057392530d77c18dee8a7492f91b;p=javassist.git fixed a bug found when an annotation includes an empty array. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@206 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/bytecode/annotation/AnnotationImpl.java b/src/main/javassist/bytecode/annotation/AnnotationImpl.java index f81b7b46..d4718ffc 100644 --- a/src/main/javassist/bytecode/annotation/AnnotationImpl.java +++ b/src/main/javassist/bytecode/annotation/AnnotationImpl.java @@ -56,12 +56,12 @@ class AnnotationImpl implements InvocationHandler { String name = method.getName(); MemberValue mv = annotation.getMemberValue(name); if (mv == null) - return getDefault(name); + return getDefault(name, method); else - return mv.getValue(classLoader, pool); + return mv.getValue(classLoader, pool, method); } - private Object getDefault(String name) + private Object getDefault(String name, Method method) throws ClassNotFoundException, RuntimeException { String classname = annotation.getTypeName(); @@ -76,7 +76,7 @@ class AnnotationImpl implements InvocationHandler { minfo.getAttribute(AnnotationDefaultAttribute.tag); if (ainfo != null) { MemberValue mv = ainfo.getDefaultValue(); - return mv.getValue(classLoader, pool); + return mv.getValue(classLoader, pool, method); } } } diff --git a/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java b/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java index 73da1637..368c82a9 100644 --- a/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java +++ b/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java @@ -17,6 +17,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Nested annotation. @@ -43,7 +44,7 @@ public class AnnotationMemberValue extends MemberValue { value = a; } - Object getValue(ClassLoader cl, ClassPool cp) + Object getValue(ClassLoader cl, ClassPool cp, Method m) throws ClassNotFoundException { return AnnotationImpl.make(cl, getType(cl), cp, value); diff --git a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java index dd586bb3..75ffe139 100644 --- a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java @@ -18,6 +18,7 @@ import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; import java.lang.reflect.Array; +import java.lang.reflect.Method; /** * Array member. @@ -49,14 +50,27 @@ public class ArrayMemberValue extends MemberValue { values = null; } - Object getValue(ClassLoader cl, ClassPool cp) throws ClassNotFoundException { - if (type == null || values == null) - throw new ClassNotFoundException("no array elements specified"); + Object getValue(ClassLoader cl, ClassPool cp, Method method) + throws ClassNotFoundException + { + if (values == null) + throw new ClassNotFoundException( + "no array elements found: " + method.getName()); int size = values.length; - Object a = Array.newInstance(type.getType(cl), size); + Class clazz; + if (type == null) { + clazz = method.getReturnType().getComponentType(); + if (clazz == null || size > 0) + throw new ClassNotFoundException("broken array type: " + + method.getName()); + } + else + clazz = type.getType(cl); + + Object a = Array.newInstance(clazz, size); for (int i = 0; i < size; i++) - Array.set(a, i, values[i].getValue(cl, cp)); + Array.set(a, i, values[i].getValue(cl, cp, method)); return a; } diff --git a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java index 7df117d7..29432b1f 100644 --- a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java +++ b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java @@ -17,6 +17,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Boolean constant value. @@ -56,7 +57,7 @@ public class BooleanMemberValue extends MemberValue { setValue(false); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Boolean(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/ByteMemberValue.java b/src/main/javassist/bytecode/annotation/ByteMemberValue.java index 3b892010..90763b09 100644 --- a/src/main/javassist/bytecode/annotation/ByteMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ByteMemberValue.java @@ -17,6 +17,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Byte constant value. @@ -56,7 +57,7 @@ public class ByteMemberValue extends MemberValue { setValue((byte)0); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Byte(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/CharMemberValue.java b/src/main/javassist/bytecode/annotation/CharMemberValue.java index 8d056d8b..f6691dfe 100644 --- a/src/main/javassist/bytecode/annotation/CharMemberValue.java +++ b/src/main/javassist/bytecode/annotation/CharMemberValue.java @@ -18,6 +18,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Char constant value. @@ -57,7 +58,7 @@ public class CharMemberValue extends MemberValue { setValue('\0'); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Character(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/ClassMemberValue.java b/src/main/javassist/bytecode/annotation/ClassMemberValue.java index f5f2fe67..cf2f510b 100644 --- a/src/main/javassist/bytecode/annotation/ClassMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ClassMemberValue.java @@ -19,6 +19,7 @@ import javassist.ClassPool; import javassist.bytecode.ConstPool; import javassist.bytecode.Descriptor; import java.io.IOException; +import java.lang.reflect.Method; /** * Class value. @@ -59,7 +60,7 @@ public class ClassMemberValue extends MemberValue { setValue("java.lang.Class"); } - Object getValue(ClassLoader cl, ClassPool cp) + Object getValue(ClassLoader cl, ClassPool cp, Method m) throws ClassNotFoundException { return loadClass(cl, getValue()); diff --git a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java index 7c987875..f2825ad4 100644 --- a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java +++ b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java @@ -18,13 +18,14 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Double floating-point number constant value. * * @author Bill Burke * @author Shigeru Chiba - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ public class DoubleMemberValue extends MemberValue { int valueIndex; @@ -58,7 +59,7 @@ public class DoubleMemberValue extends MemberValue { setValue(0.0); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Double(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/EnumMemberValue.java b/src/main/javassist/bytecode/annotation/EnumMemberValue.java index 77e07c27..effec09c 100644 --- a/src/main/javassist/bytecode/annotation/EnumMemberValue.java +++ b/src/main/javassist/bytecode/annotation/EnumMemberValue.java @@ -16,6 +16,7 @@ package javassist.bytecode.annotation; import java.io.IOException; +import java.lang.reflect.Method; import javassist.ClassPool; import javassist.bytecode.ConstPool; @@ -54,7 +55,7 @@ public class EnumMemberValue extends MemberValue { typeIndex = valueIndex = 0; } - Object getValue(ClassLoader cl, ClassPool cp) + Object getValue(ClassLoader cl, ClassPool cp, Method m) throws ClassNotFoundException { try { diff --git a/src/main/javassist/bytecode/annotation/FloatMemberValue.java b/src/main/javassist/bytecode/annotation/FloatMemberValue.java index 622a9420..7188b5e9 100644 --- a/src/main/javassist/bytecode/annotation/FloatMemberValue.java +++ b/src/main/javassist/bytecode/annotation/FloatMemberValue.java @@ -18,13 +18,14 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Floating-point number constant value. * * @author Bill Burke * @author Shigeru Chiba - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ public class FloatMemberValue extends MemberValue { int valueIndex; @@ -58,7 +59,7 @@ public class FloatMemberValue extends MemberValue { setValue(0.0F); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Float(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java index 949f3752..2f2a9076 100644 --- a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java +++ b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java @@ -18,6 +18,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Integer constant value. @@ -63,7 +64,7 @@ public class IntegerMemberValue extends MemberValue { setValue(0); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Integer(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/LongMemberValue.java b/src/main/javassist/bytecode/annotation/LongMemberValue.java index a0dd13ad..2afd4a0f 100644 --- a/src/main/javassist/bytecode/annotation/LongMemberValue.java +++ b/src/main/javassist/bytecode/annotation/LongMemberValue.java @@ -18,6 +18,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Long integer constant value. @@ -57,7 +58,7 @@ public class LongMemberValue extends MemberValue { setValue(0L); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Long(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/MemberValue.java b/src/main/javassist/bytecode/annotation/MemberValue.java index 8ee6ce9a..c976ddd3 100644 --- a/src/main/javassist/bytecode/annotation/MemberValue.java +++ b/src/main/javassist/bytecode/annotation/MemberValue.java @@ -18,6 +18,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * The value of a member declared in an annotation. @@ -39,7 +40,7 @@ public abstract class MemberValue { * Returns the value. If the value type is a primitive type, the * returned value is boxed. */ - abstract Object getValue(ClassLoader cl, ClassPool cp) + abstract Object getValue(ClassLoader cl, ClassPool cp, Method m) throws ClassNotFoundException; abstract Class getType(ClassLoader cl) throws ClassNotFoundException; diff --git a/src/main/javassist/bytecode/annotation/ShortMemberValue.java b/src/main/javassist/bytecode/annotation/ShortMemberValue.java index 7d38f4b4..3ccf3808 100644 --- a/src/main/javassist/bytecode/annotation/ShortMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ShortMemberValue.java @@ -18,6 +18,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * Short integer constant value. @@ -57,7 +58,7 @@ public class ShortMemberValue extends MemberValue { setValue((short)0); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return new Short(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/StringMemberValue.java b/src/main/javassist/bytecode/annotation/StringMemberValue.java index 80cb5e3d..970fb8f4 100644 --- a/src/main/javassist/bytecode/annotation/StringMemberValue.java +++ b/src/main/javassist/bytecode/annotation/StringMemberValue.java @@ -18,6 +18,7 @@ package javassist.bytecode.annotation; import javassist.ClassPool; import javassist.bytecode.ConstPool; import java.io.IOException; +import java.lang.reflect.Method; /** * String constant value. @@ -57,7 +58,7 @@ public class StringMemberValue extends MemberValue { setValue(""); } - Object getValue(ClassLoader cl, ClassPool cp) { + Object getValue(ClassLoader cl, ClassPool cp, Method m) { return getValue(); }