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

Duration.multiply() does not throw IllegalStateException for 1 year * 0.5

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Name: erR10175 Date: 10/30/2003


         
          The method javax.xml.datatype.Duration.multiply(BigDecimal factor)
        does not throw IllegalStateException if 1 year is multiplied by 0.5.
         
        The documentation of the method reads:

        "An IllegalStateException is thrown If the operation produces fraction
        in the months or year field. For example if you multiple one month or
        year by 0.5."

        So, even if 1 year * 0.5 is exactly 6 months, the method must throw
        IllegalStateException, to conform to the doc, because 0.5 years has
        a fraction part.

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

        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(\"P1Y\")"
                    +".multiply(new BigDecimal(\"0.5\")) returns "
                    + new Duration("P1Y").multiply(new BigDecimal("0.5"))
                    + ", expected IllegalStateException");
            }
        }
        ----------------------------------------------------

        ------------------------------------------------ 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("P1Y").multiply(new BigDecimal("0.5")) returns P0Y6M, expected IllegalStateException
        ----------------------------------------------------

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

          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: