From e2880df85352a4f46c1fc8b28c4cd08540a2daed Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Tue, 10 Jan 2006 15:59:36 +0000 Subject: 2006-01-10 Andrew John Hughes Merge of HEAD --> generics branch for the period 2005/11/27 to 2006/01/09. --- java/io/ObjectStreamClass.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'java/io/ObjectStreamClass.java') diff --git a/java/io/ObjectStreamClass.java b/java/io/ObjectStreamClass.java index f55a978d5..1df7c7ea0 100644 --- a/java/io/ObjectStreamClass.java +++ b/java/io/ObjectStreamClass.java @@ -70,6 +70,8 @@ import java.util.Vector; */ public class ObjectStreamClass implements Serializable { + static final ObjectStreamField[] INVALID_FIELDS = new ObjectStreamField[0]; + /** * Returns the ObjectStreamClass for cl. * If cl is null, or is not Serializable, @@ -78,6 +80,11 @@ public class ObjectStreamClass implements Serializable * same ObjectStreamClass object and no recalculation * will be done. * + * Warning: If this class contains an invalid serialPersistentField arrays + * lookup will not throw anything. However {@link #getFields()} will return + * an empty array and {@link java.io.ObjectOutputStream#writeObject} will throw an + * {@link java.io.InvalidClassException}. + * * @see java.io.Serializable */ public static ObjectStreamClass lookup(Class cl) @@ -155,6 +162,8 @@ public class ObjectStreamClass implements Serializable * Returns the serializable (non-static and non-transient) Fields * of the class represented by this ObjectStreamClass. The Fields * are sorted by name. + * If fields were obtained using serialPersistentFields and this array + * is faulty then the returned array of this method will be empty. * * @return the fields. */ @@ -615,6 +624,28 @@ outer: fields = getSerialPersistentFields(cl); if (fields != null) { + ObjectStreamField[] fieldsName = new ObjectStreamField[fields.length]; + System.arraycopy(fields, 0, fieldsName, 0, fields.length); + + Arrays.sort (fieldsName, new Comparator() { + public int compare(Object o1, Object o2) + { + ObjectStreamField f1 = (ObjectStreamField)o1; + ObjectStreamField f2 = (ObjectStreamField)o2; + + return f1.getName().compareTo(f2.getName()); + } + }); + + for (int i=1; i < fields.length; i++) + { + if (fieldsName[i-1].getName().equals(fieldsName[i].getName())) + { + fields = INVALID_FIELDS; + return; + } + } + Arrays.sort (fields); // Retrieve field reference. for (int i=0; i < fields.length; i++) -- cgit v1.2.1