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

Print this page

        

*** 1251,1260 **** --- 1251,1269 ---- void getObjFieldValues(Object obj, Object[] vals) { fieldRefl.getObjFieldValues(obj, vals); } /** + * Checks that the given values, from array vals starting at offset 0, + * are assignable to the given serializable object fields. + * @throws ClassCastException if any value is not assignable + */ + 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. */ void setObjFieldValues(Object obj, Object[] vals) {
*** 2068,2084 **** --- 2077,2106 ---- } } } /** + * Checks that the given values, from array vals starting at offset 0, + * are assignable to the given serializable object fields. + * @throws ClassCastException if any value is not assignable + */ + 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 **** --- 2121,2131 ---- 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();