This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

ArrayList serialization cleanup



2000-12-17  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/util/ArrayList.java (data): Declare transient.
	(serialPersistantFields): Removed.
	(readObject): Use defaultReadObject(), not readFields().
	(writeObject): Use defaultWriteObject(), not writeFields().

Index: ArrayList.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/ArrayList.java,v
retrieving revision 1.5
diff -u -r1.5 ArrayList.java
--- ArrayList.java	2000/11/27 08:30:26	1.5
+++ ArrayList.java	2000/12/17 11:48:57
@@ -33,9 +33,6 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream.GetField;
-import java.io.ObjectOutputStream.PutField;
-import java.io.ObjectStreamField;
 
 /**
  * An array-backed implementation of the List interface.  ArrayList
@@ -43,7 +40,7 @@
  * to or removing from the end of a list, checking the size, &c.
  *
  * @author        Jon A. Zeppieri
- * @version       $Id: ArrayList.java,v 1.5 2000/11/27 08:30:26 bryce Exp $
+ * @version       $Id: ArrayList.java,v 1.12 2000/12/17 07:54:39 cbj Exp $
  * @see           java.util.AbstractList
  * @see           java.util.List
  */
@@ -57,12 +54,8 @@
   int size;
 
   /** where the data is stored */
-  Object[] data;
+  transient Object[] data;
 
-  /** used for serialization -- denotes which fields are serialized */
-  private static final ObjectStreamField[] serialPersistentFields =
-    { new ObjectStreamField("size", int.class) };
-
   /** 
    * Construct a new ArrayList with the supplied initial capacity. 
    *
@@ -398,9 +391,8 @@
   {
     int i;
 
-    ObjectOutputStream.PutField fields = out.putFields();
-    fields.put("size", size);
-    out.writeFields();
+    // The 'size' field.
+    out.defaultWriteObject();
 
     // FIXME: Do we really want to serialize unused list entries??
     out.writeInt(data.length);
@@ -414,8 +406,8 @@
     int i;
     int capacity;
 
-    ObjectInputStream.GetField fields = in.readFields();
-    size = fields.get("size", 0);
+    // the `size' field.
+    in.defaultReadObject();
 
     capacity = in.readInt();
     data = new Object[capacity];

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]