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

XMLGregorianCalendar.toGregorianCalendar methods throw NPE if year is undefined

    XMLWordPrintable

    Details

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

      Backports

        Description

        Name: erR10175 Date: 03/31/2004



           Two methods in the class javax.xml.datatype.XMLGregorianCalendar

        public GregorianCalendar toGregorianCalendar()
        public GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults)

        throw NullPointerException when an instance of the XMLGregorianCalendar
        class has the year field undefined.

        The javadoc of the first method reads:
        "
        When this instance has an undefined field, this conversion relies on the
        java.util.GregorianCalendar default for its corresponding field.
        "
        And according to the javadoc the methods don't throw NullPointerException.

        The bug affects the following new JCK-15 beta2 tests:

          api/javax_xml/datatype/XMLGregorianCalendar/index.html#ConvertTo[ToGregorianCalendar006]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#ConvertTo[ToGregorianCalendar007]

        The bug is found in jdk1.5.0/beta2/b44. Those tests are in KFL with the RI bug

        4971612 XMLGregorianCalendar.toXMLFormat() uses broken format

        To reproduce the bug compile and run the following code as shown in the log below.
        ------------------------------------------ test.java
        import javax.xml.datatype.XMLGregorianCalendar;
        import java.util.GregorianCalendar;

        class test {

            public static void main(String [] args) {
                XMLGregorianCalendar xmlCalendar
                    = XMLGregorianCalendar.parse("13:14:15.162Z");
                GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
                System.out.println("OK");
            }
        }
        ----------------------------------------------------

        ------------------------------------------------ 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-b44)
        Java HotSpot(TM) Server VM (build 1.5.0-beta2-b44, mixed mode)

        Exception in thread "main" java.lang.NullPointerException
                at javax.xml.datatype.XMLGregorianCalendar.toGregorianCalendar(XMLGregorianCalendar.java:2296)
                at test.main(test.java:9)
        ----------------------------------------------------

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

          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: