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

changed behavior for class java.util.TimeZone

    XMLWordPrintable

    Details

      Description



      Name: sdC67446 Date: 06/22/99


      The behavior for methods:
          public void setID(String ID)
          public boolean hasSameRules(TimeZone other)
      of class java.util.TimeZone in jdk1.3G has been changed since
      jdk1.3F. The spec for these methods doesn't specify expected
      behavior if input parameter (ID, other) == null.

      Currently:
       setID(null) throws NPE in Kestrel-G and doesn't in Kestrel-F;
       hasSameRules(null) doesn't throw NPE in Kestrel-G and does in Kestrel-F;

      Thus the jck1.3 test api/java/util/TimeZone/index.html#misc now fails.

      The doc says:
      -------------------------------------------------------------
          /**
           * Sets the time zone ID. This does not change any other data in
           * the time zone object.
           * @param ID the new time zone ID.
           */
          public void setID(String ID)

          /**
           * Returns true if this zone has the same rule and offset as another zone.
           * That is, if this zone differs only in ID, if at all.
           * @param other the <code>TimeZone</code> object to be compared with
           * @return true if the given zone is the same as this one,
           * with the possible exception of the ID
           */
          public boolean hasSameRules(TimeZone other)

      The test demonstrating the bug:
      -------------------------------------------------------------
      import java.util.*;

      public class DummyTimeZone extends TimeZone {
          int offset;
          boolean useDaylight;

          DummyTimeZone() {
            this("");
          }

          DummyTimeZone(String ID) {
            this(ID, 0, false);
          }

          DummyTimeZone(String ID, int offset, boolean useDailight) {
            setID(ID);
            setRawOffset(offset);
            this.useDaylight = useDaylight;
          }

          public void setRawOffset(int offset) {
            this.offset = offset;
          }

          public int getRawOffset() {
            return offset;
          }

          public boolean useDaylightTime() {
            return useDaylight;
          }

          public boolean inDaylightTime(Date date) {
            return useDaylight;
          }

          public int getOffset(int era, int year, int month,
            int day, int dayOfWeek, int millis
          ) {
            return useDaylight ? offset + 3600000 : offset;
          }

          public String toString() {
            return "DummyTimeZone";
          }

          public static void main(String[] args) {
              DummyTimeZone tz = new DummyTimeZone();
              try {
                  tz.setID(null);
                  System.out.println("This is Kestrel F.");
              } catch (NullPointerException e) {
                  System.out.println("This is Kestrel G.");
              }
              try {
                  tz.hasSameRules(null);
                  System.out.println("This is Kestrel G.");
              } catch (NullPointerException e) {
                  System.out.println("This is Kestrel F.");
              }
          }
      }

      Test output:
      -------------------------------------------------------------

      ] ###@###.### ~/jtest
      ] java -version
      java version "1.3"
      Classic VM (build JDK-1.3-F, green threads, sunwjit)

      ] ###@###.### ~/jtest
      ] java DummyTimeZone
      This is Kestrel F.
      This is Kestrel F.

      .....

      ] ###@###.### ~/jtest
      ] java -version
      java version "1.3"
      Classic VM (build JDK-1.3-G, green threads, sunwjit)

      ] ###@###.### ~/jtest
      ] java DummyTimeZone
      This is Kestrel G.
      This is Kestrel G.
      ------------------------------------------------------------

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              okutsu Masayoshi Okutsu
              Reporter:
              dsvsunw Dsv Dsv (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: