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

java.util.TimeZone instances are incorrectly serialized/deserialized.

    XMLWordPrintable

Details

    • 1.2beta3
    • generic, x86, sparc
    • generic, solaris_2.5, windows_nt
    • Verified

    Description



      Name: avC70361 Date: 12/04/97



        java.util.TimeZone instances for some time zone Ids (GMT, MET, IST etc.) are
      incorrectly serialized or deserialized: the instances before and after
      serialization are not equal. This is caused by a fact that during the
      deserialization process in method java.util.SimpleTimeZone.readObject(
      ObjectInputStream) after reading object's fields the startDayOfWeek and
      endDayOfWeek fields are set to Calendar.SUNDAY value if they have been equal to
      0. But when initializing TimeZone instance with constructor TimeZone(int,
      String) these fields are set to default value 0.

      Here is the test demonstrating the bug:
      ----------TimeZoneTest.java---------
      import java.util.TimeZone;
      import java.io.*;

      public class TimeZoneTest {

        public static void main(String[] args) {
          TimeZone zone = TimeZone.getTimeZone(args[0]);
          try {
            ByteArrayOutputStream baos;
            ObjectOutputStream ostream = new ObjectOutputStream(baos = new ByteArrayOutputStream());
            ostream.writeObject(zone);
            ostream.close();
            baos.close();
            ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
            if (!zone.equals(istream.readObject())) {
              System.out.println("Time zone " + args[0] + " are not equal to serialized/deserialized one.");
            }
          } catch(Exception e) {
            System.out.println(e);
          }
        }

      }
      ---------The test outputs-----------
      #>java TimeZoneTest GMT
      Time zone GMT are not equal to serialized/deserialized one.
      #>java TimeZoneTest MET
      Time zone MET are not equal to serialized/deserialized one.
      #>java TimeZoneTest IST
      Time zone IST are not equal to serialized/deserialized one.
      ------------------------------------
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              aliusunw Alan Liu (Inactive)
              ovlasov Oleksandr Vlasov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: