From 0ab1638611d55abd242eccf1ae3e3d2c56f7c46c Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 12 Oct 2001 20:12:48 +0000 Subject: [PATCH] When setting aggregate values (arrays, DSet objects), we need to clone them before setting their value in the distributed object to prevent subsequent events from modifying those aggregate values before the originals were propagated to the clients by the networking thread. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@458 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/presents/dobj/DObject.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/presents/dobj/DObject.java b/src/java/com/threerings/presents/dobj/DObject.java index 873516531..0887bb927 100644 --- a/src/java/com/threerings/presents/dobj/DObject.java +++ b/src/java/com/threerings/presents/dobj/DObject.java @@ -1,5 +1,5 @@ // -// $Id: DObject.java,v 1.30 2001/10/12 00:29:06 mdb Exp $ +// $Id: DObject.java,v 1.31 2001/10/12 20:12:48 mdb Exp $ package com.threerings.presents.dobj; @@ -345,6 +345,35 @@ public class DObject throws ObjectAccessException { try { + // for values that contain other values (arrays and DSets), we + // need to clone them before putting them in the object + // because otherwise a subsequent event might come along and + // modify these values before the networking thread has had a + // chance to propagate this event to the clients + + // i wish i could just call value.clone() but Object declares + // clone() to be inaccessible, so we must cast the values to + // their actual types to gain access to the widened clone() + // methods + if (value instanceof DSet) { + value = ((DSet)value).clone(); + } else if (value instanceof int[]) { + value = ((int[])value).clone(); + } else if (value instanceof String[]) { + value = ((String[])value).clone(); + } else if (value instanceof byte[]) { + value = ((byte[])value).clone(); + } else if (value instanceof long[]) { + value = ((long[])value).clone(); + } else if (value instanceof float[]) { + value = ((float[])value).clone(); + } else if (value instanceof short[]) { + value = ((short[])value).clone(); + } else if (value instanceof double[]) { + value = ((double[])value).clone(); + } + + // now actually set the value getClass().getField(name).set(this, value); } catch (Exception e) {