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

method 'equals' does not work with very long durations

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      Name: erR10175 Date: 10/22/2003



        The method javax.xml.datatype.Duration.equals(Object rhs) does not detect
      equality of very long durations. For example:
          new Duration("P100000000000000000000D"),
        new Duration("PT2400000000000000000000H").

      The documentation of the method 'equals' reads:
      "Duration X is equal to Y if and only if time instant t+X and t+Y are the same for
      all the test time instants specified in the section 3.2.6.2 of the XML Schema 1.0
      specification."

      As every day contains exactly 24 hours, every x*24 hours duration equals to x days
      duration. Particularly, it hold for x = 100000000000000000000 = 1e20.

      This bug affects new test in JCK 1.5 (not yet integrated)
         api/javax_xml/datatype/Duration/index.html#DurationTests[Ctor008]

      To reproduce the bug compile and run the following code as shown
      in the log below:
      ------------------------------ test.java
      import javax.xml.datatype.Duration;

      public class test {
          public static void main(String [] args) {
              Duration d1 = new Duration("P100000000000000000000D");
              Duration d2 = new Duration("PT2400000000000000000000H");
              System.out.println("d1 = " + d1
                  + ", d1.days = " + d1.getField(Duration.DAYS)
                  + ", d1.hours = " + d1.getField(Duration.HOURS));
              System.out.println("d2 = "
                  + d2 + ", d2.days = " + d2.getField(Duration.DAYS)
                  + ", d2.hours = " + d2.getField(Duration.HOURS));
              System.out.println("d1.equals(d2) = " + d1.equals(d2));
          }
      }
      ----------------------------------------------------

      ------------------------------------------------ log
      $javac test.java
      $java -cp . -showversion test
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b24)
      Java HotSpot(TM) Server VM (build 1.5.0-beta-b24, mixed mode)

      d1 = P100000000000000000000D, d1.days = 100000000000000000000, d1.hours = null
      d2 = PT2400000000000000000000H, d2.days = null, d2.hours = 2400000000000000000000
      d1.equals(d2) = false
      ----------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kkawagucsunw Kohsuke Kawaguchi (Inactive)
              Reporter:
              reysunw Rey Rey (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: