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,8 @@ import java.util.HashMap; import java.util.Iterator; +import java.lang.reflect.Field; + import org.apache.harmony.kernel.vm.VM; import org.apache.harmony.luni.internal.nls.Messages; import org.apache.harmony.luni.util.Msg; @@ -1124,47 +1126,47 @@ } for (ObjectStreamField fieldDesc : fields) { + + // get associated Field + Field field = fieldDesc.getField(declaringClass); + // Code duplication starts, just because Java is typed if (fieldDesc.isPrimitive()) { try { switch (fieldDesc.getTypeCode()) { case 'B': - setField(obj, declaringClass, fieldDesc.getName(), - input.readByte()); + field.setByte(obj, input.readByte()); break; case 'C': - setField(obj, declaringClass, fieldDesc.getName(), - input.readChar()); + field.setChar(obj, input.readChar()); break; case 'D': - setField(obj, declaringClass, fieldDesc.getName(), - input.readDouble()); + field.setDouble(obj, input.readDouble()); break; case 'F': - setField(obj, declaringClass, fieldDesc.getName(), - input.readFloat()); + field.setFloat(obj, input.readFloat()); break; case 'I': - setField(obj, declaringClass, fieldDesc.getName(), - input.readInt()); + field.setInt(obj, input.readInt()); break; case 'J': - setField(obj, declaringClass, fieldDesc.getName(), - input.readLong()); + field.setLong(obj, input.readLong()); break; case 'S': - setField(obj, declaringClass, fieldDesc.getName(), - input.readShort()); + field.setShort(obj, input.readShort()); break; case 'Z': - setField(obj, declaringClass, fieldDesc.getName(), - input.readBoolean()); + field.setBoolean(obj, input.readBoolean()); break; default: throw new StreamCorruptedException(Msg.getString( "K00d5", fieldDesc.getTypeCode())); //$NON-NLS-1$ } } catch (NoSuchFieldError err) { + } catch (IllegalAccessException e) { + // TODO: Eliminate this debug check + System.err.println("readFieldValues failed: IllegalAccessException"); + System.exit(1); } } else { // Object type (array included). @@ -1195,10 +1197,12 @@ + fieldName })); } try { - objSetField(obj, declaringClass, fieldName, fieldDesc - .getTypeString(), toSet); + field.set(obj, toSet); } catch (NoSuchFieldError e) { // Ignored + } catch (IllegalAccessException e) { + System.err.println("FAIL2 BUG"); + System.exit(1); } } } @@ -2434,250 +2438,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 java.lang.reflect.Field; + /** * This class represents object fields that are saved to the stream, by * serialization. Classes can define the collection of fields to be dumped, @@ -47,6 +49,25 @@ private boolean isDeserialized; + private Field assocField; + + Field getField(Class declaringClass) { + if (assocField != null) { + return assocField; + } else { + String fieldName = getName(); + try { + assocField = declaringClass.getDeclaredField(fieldName); + assocField.setAccessible(true); + } catch(NoSuchFieldException e) { + // TODO: Eliminate this debug check + System.err.println("getField failed on resolving field: " + fieldName); + System.exit(1); + } + return assocField; + } + } + /** * Constructs an ObjectStreamField with the given name and the given type * Index: working_classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java =================================================================== --- working_classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java (revision 647500) +++ working_classlib/modules/luni/src/main/java/java/io/ObjectOutputStream.java (working copy) @@ -22,6 +22,8 @@ import java.lang.reflect.Proxy; import java.util.IdentityHashMap; +import java.lang.reflect.Field; + import org.apache.harmony.luni.util.Msg; /** @@ -416,197 +418,8 @@ output.flush(); } - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a boolean. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native boolean getFieldBool(Object instance, - Class declaringClass, String fieldName); /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a byte - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native byte getFieldByte(Object instance, - Class declaringClass, String fieldName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a char. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native char getFieldChar(Object instance, - Class declaringClass, String fieldName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a double. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native double getFieldDouble(Object instance, - Class declaringClass, String fieldName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a float. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native float getFieldFloat(Object instance, - Class declaringClass, String fieldName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * an int. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native int getFieldInt(Object instance, - Class declaringClass, String fieldName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a long. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native long getFieldLong(Object instance, - Class declaringClass, String fieldName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * an Object type whose name is fieldTypeName. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @param fieldTypeName Name of the class that defines the type of this field - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native Object getFieldObj(Object instance, - Class declaringClass, String fieldName, String fieldTypeName); - - /** - * Get the value of field named - * fieldName of object instance. The - * field is declared by class declaringClass. The field is supposed to be - * a short. - * - * 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 fetch private fields, except - * by the use of a native method like this one. - * - * @param instance Object whose field value we want to fetch - * @param declaringClass The class that declares the field - * @param fieldName Name of the field we want to fetch - * @return the value of the field - * - * @throws NoSuchFieldError If the field does not exist. - */ - private static native short getFieldShort(Object instance, - Class declaringClass, String fieldName); - - /** * Return the next int handle to be used to indicate cyclic * references being saved to the stream. * @@ -1160,6 +973,7 @@ } } + /** * Writes a collection of field values for the fields described by class * descriptor classDesc (an ObjectStreamClass). @@ -1182,43 +996,38 @@ throws IOException { ObjectStreamField[] fields = classDesc.fields(); Class declaringClass = classDesc.forClass(); - for (int i = 0; i < fields.length; i++) { + for(ObjectStreamField fieldDesc : fields) { try { + + // get associated Field + Field field = fieldDesc.getField(declaringClass); + // Code duplication starts, just because Java is typed - ObjectStreamField fieldDesc = fields[i]; if (fieldDesc.isPrimitive()) { switch (fieldDesc.getTypeCode()) { case 'B': - output.writeByte(getFieldByte(obj, declaringClass, - fieldDesc.getName())); + output.writeByte(field.getByte(obj)); break; case 'C': - output.writeChar(getFieldChar(obj, declaringClass, - fieldDesc.getName())); + output.writeChar(field.getChar(obj)); break; case 'D': - output.writeDouble(getFieldDouble(obj, - declaringClass, fieldDesc.getName())); + output.writeDouble(field.getDouble(obj)); break; case 'F': - output.writeFloat(getFieldFloat(obj, - declaringClass, fieldDesc.getName())); + output.writeFloat(field.getFloat(obj)); break; case 'I': - output.writeInt(getFieldInt(obj, declaringClass, - fieldDesc.getName())); + output.writeInt(field.getInt(obj)); break; case 'J': - output.writeLong(getFieldLong(obj, declaringClass, - fieldDesc.getName())); + output.writeLong(field.getLong(obj)); break; case 'S': - output.writeShort(getFieldShort(obj, - declaringClass, fieldDesc.getName())); + output.writeShort(field.getShort(obj)); break; case 'Z': - output.writeBoolean(getFieldBool(obj, - declaringClass, fieldDesc.getName())); + output.writeBoolean(field.getBoolean(obj)); break; default: throw new IOException( @@ -1227,12 +1036,11 @@ } } else { // Object type (array included). - Object field = getFieldObj(obj, declaringClass, fieldDesc - .getName(), fieldDesc.getTypeString()); + Object objField = field.get(obj); if (fieldDesc.isUnshared()) { - writeUnshared(field); + writeUnshared(objField); } else { - writeObject(field); + writeObject(objField); } } } catch (NoSuchFieldError nsf) { @@ -1241,6 +1049,10 @@ // (in writeObject) so we end up using the default mechanism and // fail to set the emulated field throw new InvalidClassException(classDesc.getName()); + } catch (IllegalAccessException e) { + // TODO: Eliminate this debug check + System.err.println("writeFieldValues failed: IllegalAccessException"); + System.exit(1); } } } @@ -2013,8 +1825,15 @@ // Only write field "name" for enum class, which is the second field of // enum, that is fields[1]. Ignore all non-fields and fields.length < 2 if (null != fields && fields.length > 1) { - String str = (String) getFieldObj(object, declaringClass, fields[1] - .getName(), fields[1].getTypeString()); + String str = null; + try { + str = (String) fields[1].getField(declaringClass).get(object); + } catch (IllegalAccessException e) { + // TODO: Eliminate this debug check + System.err.println("writeNewEnum failed: IllegalAccessException"); + System.exit(1); + } + Integer strhandle = null; if (!unshared) { strhandle = dumpCycle(str); Index: working_classlib/modules/luni/src/main/native/luni/shared/oos.c =================================================================== --- working_classlib/modules/luni/src/main/native/luni/shared/oos.c (revision 647500) +++ working_classlib/modules/luni/src/main/native/luni/shared/oos.c (working copy) @@ -17,206 +17,3 @@ #include "jni.h" -JNIEXPORT jlong JNICALL -Java_java_io_ObjectOutputStream_getFieldLong (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "J"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jlong) 0L; - } - else - { - return (*env)->GetLongField (env, targetObject, fid); - } -} - -JNIEXPORT jshort JNICALL -Java_java_io_ObjectOutputStream_getFieldShort (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "S"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jshort) 0; - } - else - { - return (*env)->GetShortField (env, targetObject, fid); - } -} - -JNIEXPORT jdouble JNICALL -Java_java_io_ObjectOutputStream_getFieldDouble (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "D"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jdouble) 0.0; - } - else - { - return (*env)->GetDoubleField (env, targetObject, fid); - } -} - -JNIEXPORT jboolean JNICALL -Java_java_io_ObjectOutputStream_getFieldBool (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "Z"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jboolean) 0; - } - else - { - return (*env)->GetBooleanField (env, targetObject, fid); - } -} - -JNIEXPORT jbyte JNICALL -Java_java_io_ObjectOutputStream_getFieldByte (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "B"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jbyte) 0; - } - else - { - return (*env)->GetByteField (env, targetObject, fid); - } -} - -JNIEXPORT jfloat JNICALL -Java_java_io_ObjectOutputStream_getFieldFloat (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "F"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jfloat) 0.0f; - } - else - { - return (*env)->GetFloatField (env, targetObject, fid); - } - -} - -JNIEXPORT jchar JNICALL -Java_java_io_ObjectOutputStream_getFieldChar (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "C"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jchar) 0; - } - else - { - return (*env)->GetCharField (env, targetObject, fid); - } -} - -JNIEXPORT jobject JNICALL -Java_java_io_ObjectOutputStream_getFieldObj (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName, - jobject fieldTypeName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - const char *fieldTypeNameInC = - (*env)->GetStringUTFChars (env, fieldTypeName, NULL); - jfieldID fid = - (*env)->GetFieldID (env, declaringClass, fieldNameInC, fieldTypeNameInC); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - (*env)->ReleaseStringUTFChars (env, fieldTypeName, fieldTypeNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jobject) 0; - } - else - { - return (*env)->GetObjectField (env, targetObject, fid); - } -} - -JNIEXPORT jint JNICALL -Java_java_io_ObjectOutputStream_getFieldInt (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName) -{ - const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "I"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid == 0) - { - /* Field not found. I believe we must throw an exception here */ - return (jint) 0; - } - else - { - return (*env)->GetIntField (env, targetObject, fid); - } -} Index: working_classlib/modules/luni/src/main/native/luni/shared/ois.c =================================================================== --- working_classlib/modules/luni/src/main/native/luni/shared/ois.c (revision 647500) +++ working_classlib/modules/luni/src/main/native/luni/shared/ois.c (working copy) @@ -17,148 +17,6 @@ #include "jni.h" -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2Z - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jboolean newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "Z"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetBooleanField (env, targetObject, fid, newValue); - } -} - -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2C - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jchar newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "C"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetCharField (env, targetObject, fid, newValue); - } -} - -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2I - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jint newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "I"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetIntField (env, targetObject, fid, newValue); - } -} - -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2F - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jfloat newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "F"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetFloatField (env, targetObject, fid, newValue); - } -} - -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2D - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jdouble newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "D"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetDoubleField (env, targetObject, fid, newValue); - } - -} - -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2S - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jshort newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "S"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetShortField (env, targetObject, fid, newValue); - } - -} - -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2J - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jlong newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "J"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetLongField (env, targetObject, fid, newValue); - } -} - JNIEXPORT jobject JNICALL Java_java_io_ObjectInputStream_newInstance (JNIEnv * env, jclass clazz, jobject instantiationClass, @@ -186,48 +44,3 @@ } -JNIEXPORT void JNICALL - Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2B - (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass, - jobject fieldName, jbyte newValue) -{ - const char *fieldNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "B"); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetByteField (env, targetObject, fid, newValue); - } -} - -JNIEXPORT void JNICALL -Java_java_io_ObjectInputStream_objSetField (JNIEnv * env, jclass clazz, - jobject targetObject, - jobject declaringClass, - jobject fieldName, - jobject fieldTypeName, - jobject newValue) -{ - const char *fieldNameInC, *fieldTypeNameInC; - jfieldID fid; - if (targetObject == NULL) - return; - fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL); - fieldTypeNameInC = (*env)->GetStringUTFChars (env, fieldTypeName, NULL); - fid = - (*env)->GetFieldID (env, declaringClass, fieldNameInC, fieldTypeNameInC); - (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC); - (*env)->ReleaseStringUTFChars (env, fieldTypeName, fieldTypeNameInC); - - /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ - if (fid != 0) - { - (*env)->SetObjectField (env, targetObject, fid, newValue); - } -}