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

XMLGregorianCalendar.normalize throws IllegalArgumentException

XMLWordPrintable

    • 1.3
    • generic
    • generic

        Name: erR10175 Date: 05/18/2004



         The following method of the class javax.xml.datatype.XMLGregorianCalendar

        public abstract XMLGregorianCalendar normalize()

        throws IllegalArgumentException if the time zone is UTC or undefined.

        The javadoc of the method specifies no exception to be thrown. Instead
        it refers to the W3C XML Schema Part 2, Section 3.2.7.3 which reads:
        W3C XML Schema Part 2, Section 3.2.7.3
        "
        A.Normalize P and Q. That is, if there is a timezone present, but it is not Z,
        convert it to Z using the addition operation defined in Adding durations
        to dateTimes
        "

        So in both cases (UTC and undefined) the method should leave
        the XMLGregorianCalendar instance unchanged and return.

        This bug affects new test in JCK 1.5
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#Normalize[Normalize001]

        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.XMLGregorianCalendar;
        import javax.xml.datatype.DatatypeFactory;

        class test {

            static final String [] normalizeValues = {
                "2000-01-16T12:00:00Z",
                "2000-01-16T12:00:00",
            };

            public static void main(String [] args) throws Exception {
                DatatypeFactory df = DatatypeFactory.newInstance();
                String status = "Passed.";
                for(int i = 0; i < normalizeValues.length; ++i) {
                    XMLGregorianCalendar lhs = df.newXMLGregorianCalendar(normalizeValues[i]);
                    try {
                        lhs.normalize();
                    } catch (Exception e) {
                        status = "Failed.";
                        System.out.println("'" + normalizeValues[i] + "'.normalize()"
                                    + " throws " + e);
                    }
                }
                System.out.println(status);
            }
        }
        ----------------------------------------------------

        ------------------------------------------------ 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)

        '2000-01-16T12:00:00Z'.normalize() throws java.lang.IllegalArgumentException: all the fields are null
        '2000-01-16T12:00:00'.normalize() throws java.lang.IllegalArgumentException: MINUTES is negative
        Failed.
        ----------------------------------------------------

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

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: