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

(str) String.CASE_INSENSITIVE_ORDER should override readResolve()

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b17
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

      Name: rmT116609 Date: 04/21/2004


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

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

      A DESCRIPTION OF THE PROBLEM :
      The comparator given by String.CASE_INSENSITIVE_ORDER (a nested class String.CaseInsensitiveComparator) does not implement equals. Thus you can't tell if two instances of this object actually represent the same order. Multiple instances arise in the if you serialize and later deserialize an object refering to an instance of this class. The class should either implement equals (and hashCode) or better it should implement readReplace to ensure that there is always only one instance.



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.ByteArrayInputStream;
      import java.io.ByteArrayOutputStream;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;

      public class TestCaseInsensitive
      {
      public static void main(String[] args)
      {
      try
      {
      ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(outBuffer);
      out.writeObject(String.CASE_INSENSITIVE_ORDER);
      out.close();
      ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
      ObjectInputStream in = new ObjectInputStream(inBuffer);
      Object result = in.readObject();
      in.close();
      if (String.CASE_INSENSITIVE_ORDER.equals(result))
      System.out.println("Correct result");
      else
      System.out.println("Value restored from serial form does not match original!");
      }
      catch (Exception ex)
      {
      ex.printStackTrace();
      }
      }
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 250087)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmocek Darryl Mocek
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: