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

DatatypeFactory.newXMLGregorianCalendar(..) does not accept milliseconds

    Details

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

      Backports

        Description

        Name: erR10175 Date: 05/19/2004



         Two following methods of the class javax.xml.datatype.DatatypeFactory

        public XMLGregorianCalendar newXMLGregorianCalendar(int year, int month, int day, int hour,
                                               int minute, int second, int millisecond, int timezone)
        public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, int minutes, int seconds,
                                               int milliseconds, int timezone)

        throw IllegalArgumentException if the milliseconds parameter is greater than 1.

        The javadoc of the class javax.xml.datatype.XMLGregorianCalendar specifies the millisecond
        field as the convenience millisecond precision of value of getFractionalSecond() so that
        the following equation is satisfied:

          getMillisecond()/1000 == getFractionalSecond()

        As the FractionalSecond is in range from 0.0 to 1.0, the millisecond may vary from 0 to
        1000, and thus the value '2' should be accepted but the RI throws IllegalArgumentException
        (see the test below).

        This bug affects new tests in JCK 1.5
          api/javax_xml/datatype/DatatypeFactory/index.html#NewXMLGregorianCalendar[NewXMLGregorianCalendar005]
          api/javax_xml/datatype/DatatypeFactory/index.html#NewXMLGregorianCalendar[NewXMLGregorianCalendarTime005]

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

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

        class test {

            public static void main(String [] args) throws Exception {
                DatatypeFactory df = DatatypeFactory.newInstance();
                df.newXMLGregorianCalendar(9999, 12, 31, 23, 59, 59, 0, 840);
                System.out.println("Passed. 0");
                df.newXMLGregorianCalendar(9999, 12, 31, 23, 59, 59, 1, 840);
                System.out.println("Passed. 1");
                df.newXMLGregorianCalendar(9999, 12, 31, 23, 59, 59, 2, 840);
                System.out.println("Passed. 2");
            }
        }
        ----------------------------------------------------

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

        Passed. 0
        Passed. 1
        Exception in thread "main" java.lang.IllegalArgumentException: invalid value 2 for fractional second
                at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.setFractionalSecond(XMLGregorianCalendarImpl.java:2672)
                at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.setTime(XMLGregorianCalendarImpl.java:1316)
                at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.<init>(XMLGregorianCalendarImpl.java:484)
                at com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(DatatypeFactoryImpl.java:326)
                at javax.xml.datatype.DatatypeFactory.newXMLGregorianCalendar(DatatypeFactory.java:733)
                at test.main(test.java:11)
        ----------------------------------------------------

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jsuttorsunw Jeff Suttor (Inactive)
                  Reporter:
                  reysunw Rey Rey (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: