src/java.base/share/classes/java/io/ObjectStreamClass.java

Print this page

        

*** 1250,1259 **** --- 1250,1263 ---- */ void getObjFieldValues(Object obj, Object[] vals) { fieldRefl.getObjFieldValues(obj, vals); } + void checkObjFieldValueTypes(Object obj, Object[] vals) { + fieldRefl.checkObjectFieldValueTypes(obj, vals); + } + /** * Sets the serializable object fields of object obj using values from * array vals starting at offset 0. It is the responsibility of the caller * to ensure that obj is of the proper type if non-null. */
*** 2067,2084 **** --- 2071,2096 ---- throw new InternalError(); } } } + void checkObjectFieldValueTypes(Object obj, Object[] vals) { + setObjFieldValues(obj, vals, true); + } + /** * Sets the serializable object fields of object obj using values from * array vals starting at offset 0. The caller is responsible for * ensuring that obj is of the proper type; however, attempts to set a * field with a value of the wrong type will trigger an appropriate * ClassCastException. */ void setObjFieldValues(Object obj, Object[] vals) { + setObjFieldValues(obj, vals, false); + } + + private void setObjFieldValues(Object obj, Object[] vals, boolean dryRun) { if (obj == null) { throw new NullPointerException(); } for (int i = numPrimFields; i < fields.length; i++) { long key = writeKeys[i];
*** 2099,2108 **** --- 2111,2121 ---- f.getDeclaringClass().getName() + "." + f.getName() + " of type " + f.getType().getName() + " in instance of " + obj.getClass().getName()); } + if (!dryRun) unsafe.putObject(obj, key, val); break; default: throw new InternalError();