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

Duration.multiply() does not multiply seconds

XMLWordPrintable

    • 1.3
    • generic
    • generic

        Name: erR10175 Date: 10/30/2003


         
          The following methods of the class javax.xml.datatype.Duration
          
        public Duration multiply(int factor)
        public final Duration multiply(BigDecimal factor)
         
        does not multiply seconds in the duration.
         
        The documentation of the methods reads:

        "Computes a new duration whose value is factor times longer than the value
        of this duration."

        So for example, the duration "PT1M1S" and the factor 2 must produce "PT2M2S",
        but both methods return "PT2M1S".

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

        The bug is found in jdk1.5.0/beta/b25.

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

        public class test {

            public static void main(String [] args) {
                System.out.println("new Duration(\"PT1M1S\").multiply(2) returns "
                    + new Duration("PT1M1S").multiply(2)
                    + ", expected PT2M2S");
                System.out.println("new Duration(\"PT1M1S\")"
                    +".multiply(new BigDecimal(\"2\")) returns "
                    + new Duration("PT1M1S").multiply(new BigDecimal("2"))
                    + ", expected PT2M2S");
            }
        }
        ----------------------------------------------------

        ------------------------------------------------ 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-b25)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b25, mixed mode)

        new Duration("PT1M1S").multiply(2) returns PT2M1S, expected PT2M2S
        new Duration("PT1M1S").multiply(new BigDecimal("2")) returns PT2M1S, expected PT2M2S
        ----------------------------------------------------


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

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: