Sfoglia il codice sorgente

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
tags/rel_3_17_1_ga
chiba 18 anni fa
parent
commit
5292871f7d

+ 4
- 4
src/main/javassist/bytecode/annotation/AnnotationImpl.java Vedi File

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

+ 2
- 1
src/main/javassist/bytecode/annotation/AnnotationMemberValue.java Vedi File

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

+ 19
- 5
src/main/javassist/bytecode/annotation/ArrayMemberValue.java Vedi File

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

+ 2
- 1
src/main/javassist/bytecode/annotation/BooleanMemberValue.java Vedi File

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


+ 2
- 1
src/main/javassist/bytecode/annotation/ByteMemberValue.java Vedi File

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


+ 2
- 1
src/main/javassist/bytecode/annotation/CharMemberValue.java Vedi File

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


+ 2
- 1
src/main/javassist/bytecode/annotation/ClassMemberValue.java Vedi File

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

+ 3
- 2
src/main/javassist/bytecode/annotation/DoubleMemberValue.java Vedi File

@@ -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 <a href="mailto:bill@jboss.org">Bill Burke</a>
* @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());
}


+ 2
- 1
src/main/javassist/bytecode/annotation/EnumMemberValue.java Vedi File

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

+ 3
- 2
src/main/javassist/bytecode/annotation/FloatMemberValue.java Vedi File

@@ -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 <a href="mailto:bill@jboss.org">Bill Burke</a>
* @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());
}


+ 2
- 1
src/main/javassist/bytecode/annotation/IntegerMemberValue.java Vedi File

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


+ 2
- 1
src/main/javassist/bytecode/annotation/LongMemberValue.java Vedi File

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


+ 2
- 1
src/main/javassist/bytecode/annotation/MemberValue.java Vedi File

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

+ 2
- 1
src/main/javassist/bytecode/annotation/ShortMemberValue.java Vedi File

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


+ 2
- 1
src/main/javassist/bytecode/annotation/StringMemberValue.java Vedi File

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


Loading…
Annulla
Salva