UUIDs left in inconsistent state by deserialization

XMLWordPrintable

    • b46
    • sparc
    • solaris_9



      Name: gm110360 Date: 03/16/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Server VM (build 1.5.0-beta-b32c, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      LInux 2.4.20-30.9
      SunOS 5.9 Generic_112233-08
      Windows 2000
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
      Deserializing an UUID through ObjectOutputStream.readObject() returns an UUID object that is left in an inconsistent state, namely its transient member variables (such as variant) are not restored properly. This causes UUIDs that are otherwise bit-for-bit identical to compare as unequal by UUID.equals(). Moreover, UUID.compareTo() would throw an IllegalArgumentException comparing such identical UUIDs.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Strings equal: true
      Objects equal: true
      Variants equal: true
      a.variant(): 2
      b.variant(): 2

      ACTUAL -
      Strings equal: true
      Objects equal: false
      Variants equal: false
      a.variant(): 2
      b.variant(): 0


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      class CrappyUUID
      {
          public static void main(String[] args) throws Exception
          {
      UUID a = UUID.randomUUID();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(a);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bais);
      UUID b = (UUID)ois.readObject();

      System.out.println("Strings equal: " + a.toString().equals(b.toString()));
      System.out.println("Objects equal: " + a.equals(b));
      System.out.println("Variants equal: " + (a.variant() == b.variant()));
      System.out.println("a.variant(): " + a.variant());
      System.out.println("b.variant(): " + b.variant());
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      For classes containing UUID members, override readObject/writeObject to serialize/deserialize UUIDs through their string representation.
      (Incident Review ID: 243694)
      ======================================================================

            Assignee:
            Michael Mccloskey (Inactive)
            Reporter:
            Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: