fix various Android test suite regressions and add more reflection tests

Most of these regressions were simply due to testing a lot more stuff,
esp. annotations and reflection, revealing holes in the Android
compatibility code.  There are still some holes, but at least the
suite is passing (except for a fragile test in Serialize.java which I
will open an issue for).

Sorry this is such a big commit; there was more to address than I
initially expected.
This commit is contained in:
Joel Dice
2013-12-06 15:45:46 -07:00
parent 39e3850ed8
commit 7056315c18
9 changed files with 769 additions and 128 deletions

View File

@ -161,6 +161,40 @@ public class Field<T> extends AccessibleObject {
return ((Double) get(instance)).doubleValue();
}
private boolean matchType(Object value) {
switch (vmField.code) {
case ByteField:
return value instanceof Byte;
case BooleanField:
return value instanceof Boolean;
case CharField:
return value instanceof Character;
case ShortField:
return value instanceof Short;
case IntField:
return value instanceof Integer;
case LongField:
return value instanceof Long;
case FloatField:
return value instanceof Float;
case DoubleField:
return value instanceof Double;
case ObjectField:
return value == null || getType().isInstance(value);
default:
throw new Error();
}
}
public void set(Object instance, Object value)
throws IllegalAccessException
{
@ -173,6 +207,10 @@ public class Field<T> extends AccessibleObject {
throw new IllegalArgumentException();
}
if (! matchType(value)) {
throw new IllegalArgumentException();
}
Classes.initialize(vmField.class_);
switch (vmField.code) {
@ -212,14 +250,7 @@ public class Field<T> extends AccessibleObject {
break;
case ObjectField:
if (value == null || getType().isInstance(value)) {
setObject(target, vmField.offset, value);
} else {
throw new IllegalArgumentException
("needed " + getType() + ", got "
+ value.getClass().getName() +
" when setting " + Class.getName(vmField.class_) + "." + getName());
}
setObject(target, vmField.offset, value);
break;
default: