Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6431845

Bug in serialization of ArrayBlockingQueue

XMLWordPrintable

    • b89
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Internal put and take indeces of java.util.concurrent.ArrayBlockingQueue are transient causing serialization to loose them and mixing up the queue items after deserialization.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached source script.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      First: 0
      Second: 1

      ACTUAL -
      First: 0
      Second: null


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.util.concurrent.*;

      /**
       * Test case.
       */
      abstract class SerializeQueue
      {
          /**
           * Evaluates this script.
           *
           * @param args the arguments.
           * @throws Exception on errors.
           */
          public static void main(String[] args) throws Exception
          {
              BlockingQueue queue = new ArrayBlockingQueue(5);
              for (int i = 0; i < 5; i++)
              {
                  queue.add(new Integer(i));
              }
              Integer first = (Integer) queue.poll();
              System.out.println("First: " + first);
              
              FileOutputStream fos = new FileOutputStream("c:\\temp\\t.tmp");
              ObjectOutputStream oos = new ObjectOutputStream(fos);
              oos.writeObject(queue);
              oos.close();
              fos.close();
              
              FileInputStream fis = new FileInputStream("c:\\temp\\t.tmp");
              ObjectInputStream ois = new ObjectInputStream(fis);
              queue = (BlockingQueue) ois.readObject();
              ois.close();
              fis.close();

              Integer second = (Integer) queue.poll();
              System.out.println("Second: " + second);
          }
      }

      ---------- END SOURCE ----------

            martin Martin Buchholz
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: