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

Duration: the compare method throws IllegalArgumentException for "-PT0.001S"

XMLWordPrintable

    • beta2
    • generic
    • generic
    • Verified

      Name: erR10175 Date: 02/06/2004



         The method of class javax.xml.datatype.Duration

      public static int compare(Duration lhs, Duration rhs)

      throws IllegalArgumentException with the following message "invalid value
      -0.001 for fractional second", if "-PT0.001S" is being compared.

      The only exception is specified to be throwable from the method is
      the NullPointerException if at least one of the parameters is null.
      The test (see below) calls the method with the valid non-null durations:
      "P0Y" and "-PT0.001S" and results in the IllegalArgumentException,
      but expected to return Duration.GREATER.

      The bug is found in jdk1.5.0/beta/b37 and is not reproducible in jdk1.5.0/beta/b35.

      This bug affects new test in JCK 1.5
           api/javax_xml/datatype/Duration/index.html#Ctor[Ctor007]

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

      public class test {
           public static void main(String [] args) {
               Duration d0 = new Duration("P0Y");
               Duration d1 = new Duration("-PT0.001S");
               System.out.println("comparing durations " + d0 + " and " + d1);
               int returned = Duration.compare(d0, d1);
               if (Duration.GREATER != returned) {
                   System.out.println("Failed: returned " + returned
                                    + ", expected " + Duration.GREATER);
               } else {
                   System.out.println("OK");
               }
           }
      }
      ----------------------------------------------------

      ----------------------------------------------- log1
      $javac test.java && java -showversion test
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b35)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b35, mixed mode)

      comparing durations P0Y and -PT0.001S
      OK
      ----------------------------------------------------

      ----------------------------------------------- log2
      $javac test.java && java -showversion test
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)

      comparing durations P0Y and -PT0.001S
      Exception in thread "main" java.lang.IllegalArgumentException: invalid value -0.001 for fractional second
               at javax.xml.datatype.XMLGregorianCalendar.setFractionalSecond(XMLGregorianCalendar.java:2503)
               at javax.xml.datatype.XMLGregorianCalendar.add(XMLGregorianCalendar.java:1935)
               at javax.xml.datatype.Duration.compare(Duration.java:645)
               at test.main(test.java:8)
      ----------------------------------------------------

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

            jfialli Joe Fialli
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: