diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-01-10 15:59:36 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-01-10 15:59:36 +0000 |
commit | e2880df85352a4f46c1fc8b28c4cd08540a2daed (patch) | |
tree | aee81230bdbf73bd817662e0ce7a4665939ab41d /java/io/ObjectStreamClass.java | |
parent | 05f169147352fa3eeb9726f3d57597a83eb7d64d (diff) | |
download | classpath-e2880df85352a4f46c1fc8b28c4cd08540a2daed.tar.gz |
2006-01-10 Andrew John Hughes <gnu_andrew@member.fsf.org>
Merge of HEAD --> generics branch for the period
2005/11/27 to 2006/01/09.
Diffstat (limited to 'java/io/ObjectStreamClass.java')
-rw-r--r-- | java/io/ObjectStreamClass.java | 31 |
1 files changed, 31 insertions, 0 deletions
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 <code>ObjectStreamClass</code> for <code>cl</code>. * If <code>cl</code> is null, or is not <code>Serializable</code>, @@ -78,6 +80,11 @@ public class ObjectStreamClass implements Serializable * same <code>ObjectStreamClass</code> 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++) |