You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/09/20 16:03:58 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestCursorableLinkedList.java

scolebourne    2003/09/20 07:03:58

  Modified:    collections/src/java/org/apache/commons/collections
                        CursorableLinkedList.java
               collections/src/test/org/apache/commons/collections
                        TestCursorableLinkedList.java
  Log:
  Fix problem with Serialization and Cursors hidden from original tests.
  Reported by Rodney
  
  Revision  Changes    Path
  1.17      +13 -8     jakarta-commons/collections/src/java/org/apache/commons/collections/CursorableLinkedList.java
  
  Index: CursorableLinkedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CursorableLinkedList.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CursorableLinkedList.java	31 Aug 2003 17:26:43 -0000	1.16
  +++ CursorableLinkedList.java	20 Sep 2003 14:03:57 -0000	1.17
  @@ -91,6 +91,9 @@
    */
   public class CursorableLinkedList implements List, Serializable {
       //  TODO: use weak references to cursors in case they aren't closed directly
  +    
  +    /** Ensure serialization compatability */    
  +    private static final long serialVersionUID = 8836393098519411393L;
   
       //--- public methods ---------------------------------------------
   
  @@ -897,7 +900,7 @@
           out.defaultWriteObject();
           out.writeInt(_size);
           Listable cur = _head.next();
  -        while(cur != null) {
  +        while (cur != null) {
               out.writeObject(cur.value());
               cur = cur.next();
           }
  @@ -906,9 +909,11 @@
       private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
           in.defaultReadObject();
           _size = 0;
  +        _modCount = 0;
  +        _cursors = new ArrayList();
           _head = new Listable(null,null,null);
           int size = in.readInt();
  -        for(int i=0;i<size;i++) {
  +        for (int i=0;i<size;i++) {
               this.add(in.readObject());
           }
       }
  @@ -916,7 +921,7 @@
       //--- protected attributes ---------------------------------------
   
       /** The number of elements in me. */
  -    transient protected int _size = 0;
  +    protected transient int _size = 0;
   
       /**
        * A sentry node.
  @@ -930,16 +935,16 @@
        * {@link org.apache.commons.collections.CursorableLinkedList.Listable} 
        * is the first or last element in the list.
        */
  -    transient protected Listable _head = new Listable(null,null,null);
  +    protected transient Listable _head = new Listable(null,null,null);
   
       /** Tracks the number of structural modifications to me. */
  -    protected int _modCount = 0;
  +    protected transient int _modCount = 0;
   
       /**
        * A list of the currently {@link CursorableLinkedList.Cursor}s currently
        * open in this list.
        */
  -    protected List _cursors = new ArrayList();
  +    protected transient List _cursors = new ArrayList();
   
       //--- inner classes ----------------------------------------------
   
  
  
  
  1.10      +27 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestCursorableLinkedList.java
  
  Index: TestCursorableLinkedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCursorableLinkedList.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestCursorableLinkedList.java	31 Aug 2003 17:28:43 -0000	1.9
  +++ TestCursorableLinkedList.java	20 Sep 2003 14:03:57 -0000	1.10
  @@ -932,6 +932,29 @@
           assertTrue(list.equals(list2));
       }
   
  +    public void testSerializationWithOpenCursor() throws Exception {
  +        list.add("A");
  +        list.add("B");
  +        list.add("C");
  +        list.add("D");
  +        list.add("E");
  +        CursorableLinkedList.Cursor cursor = list.cursor();
  +
  +        java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream();
  +        java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(buf);
  +        out.writeObject(list);
  +        out.flush();
  +        out.close();
  +
  +        java.io.ByteArrayInputStream bufin = new java.io.ByteArrayInputStream(buf.toByteArray());
  +        java.io.ObjectInputStream in = new java.io.ObjectInputStream(bufin);
  +        Object list2 = in.readObject();
  +
  +        assertTrue(list != list2);
  +        assertTrue(list2.equals(list));
  +        assertTrue(list.equals(list2));
  +    }
  +
       public void testLongSerialization() throws Exception {
           // recursive serialization will cause a stack
           // overflow exception with long lists
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org