Index: working_classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java
===================================================================
--- working_classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java (revision 647500)
+++ working_classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java (working copy)
@@ -30,6 +30,9 @@
import java.util.HashMap;
import java.util.Iterator;
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+import org.apache.harmony.misc.accessors.AccessorFactory;
+
import org.apache.harmony.kernel.vm.VM;
import org.apache.harmony.luni.internal.nls.Messages;
import org.apache.harmony.luni.util.Msg;
@@ -119,6 +122,8 @@
PRIMITIVE_CLASSES.put("double", double.class); //$NON-NLS-1$
}
+ private ObjectAccessor accessor = AccessorFactory.getObjectAccessor();
+
// Internal type used to keep track of validators & corresponding priority
static class InputValidationDesc {
ObjectInputValidation validator;
@@ -1124,41 +1129,39 @@
}
for (ObjectStreamField fieldDesc : fields) {
+
+ // get associated Field
+ long fieldID = fieldDesc.getFieldID(accessor, declaringClass);
+
+ if (fieldID == ObjectStreamField.FIELD_IS_ABSENT) continue;
+
// Code duplication starts, just because Java is typed
if (fieldDesc.isPrimitive()) {
try {
switch (fieldDesc.getTypeCode()) {
case 'B':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readByte());
+ accessor.setByte(obj, fieldID, input.readByte());
break;
case 'C':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readChar());
+ accessor.setChar(obj, fieldID, input.readChar());
break;
case 'D':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readDouble());
+ accessor.setDouble(obj, fieldID, input.readDouble());
break;
case 'F':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readFloat());
+ accessor.setFloat(obj, fieldID, input.readFloat());
break;
case 'I':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readInt());
+ accessor.setInt(obj, fieldID, input.readInt());
break;
case 'J':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readLong());
+ accessor.setLong(obj, fieldID, input.readLong());
break;
case 'S':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readShort());
+ accessor.setShort(obj, fieldID, input.readShort());
break;
case 'Z':
- setField(obj, declaringClass, fieldDesc.getName(),
- input.readBoolean());
+ accessor.setBoolean(obj, fieldID, input.readBoolean());
break;
default:
throw new StreamCorruptedException(Msg.getString(
@@ -1195,8 +1198,7 @@
+ fieldName }));
}
try {
- objSetField(obj, declaringClass, fieldName, fieldDesc
- .getTypeString(), toSet);
+ accessor.setObject(obj, fieldID, toSet);
} catch (NoSuchFieldError e) {
// Ignored
}
@@ -2434,250 +2436,6 @@
}
/**
- * Set a given declared field named fieldName of
- * instance to the new byte value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, byte value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new char value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, char value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new double value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, double value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new float value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, float value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new int value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, int value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new long value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, long value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new value value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * Class which declares the field
- * @param fieldName
- * Name of the field to set
- * @param fieldTypeName
- * Name of the class defining the type of the field
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void objSetField(Object instance,
- Class> declaringClass, String fieldName, String fieldTypeName,
- Object value) throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new short value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, short value)
- throws NoSuchFieldError;
-
- /**
- * Set a given declared field named fieldName of
- * instance to the new boolean value
- * value.
- *
- * This method could be implemented non-natively on top of java.lang.reflect
- * implementations that support the setAccessible API, at the
- * expense of extra object creation (java.lang.reflect.Field). Otherwise
- * Serialization could not set private fields, except by the use of a native
- * method like this one.
- *
- * @param instance
- * Object whose field to set
- * @param declaringClass
- * instance's declaring class
- * @param fieldName
- * Name of the field to set
- * @param value
- * New value for the field
- *
- * @throws NoSuchFieldError
- * If the field does not exist.
- */
- private static native void setField(Object instance,
- Class> declaringClass, String fieldName, boolean value)
- throws NoSuchFieldError;
-
- /**
* Skips length bytes of primitive data from the receiver. It
* should not be used to skip bytes at any arbitrary position; just when
* reading primitive data types (ints, chars, etc).
Index: working_classlib/modules/luni/src/main/java/java/io/ObjectStreamField.java
===================================================================
--- working_classlib/modules/luni/src/main/java/java/io/ObjectStreamField.java (revision 647500)
+++ working_classlib/modules/luni/src/main/java/java/io/ObjectStreamField.java (working copy)
@@ -21,6 +21,8 @@
import java.util.Arrays;
import java.util.Comparator;
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+
/**
* This class represents object fields that are saved to the stream, by
* serialization. Classes can define the collection of fields to be dumped,
@@ -31,6 +33,9 @@
*/
public class ObjectStreamField implements Comparable