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

XMLGregorianCalendar.toGregorianCalendar(..) throws NPE if 'defaults' is null

    Details

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

      Backports

        Description

        Name: erR10175 Date: 05/18/2004



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

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

        throws NullPointerException if the 'defaults' parameter is null.

        The javadoc of the method specifies no exception to be thrown and the 'defaults'
        parameter usage is specified as follows:
        "
        Parameters:
            ...
            defaults - provide default field values to use when corresponding field for this
                       instance is FIELD_UNDEFINED or null. If defaultsis null or a field within
                       the specified defaults is undefined, just use java.util.GregorianCalendar
                       defaults.
        "
        So the 'defaults' parameter's value null is legal and should not cause any exception.

        This bug affects new tests in JCK 1.5
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#ConvertTo[ToGregorianCalendar008]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#ConvertTo[ToGregorianCalendar009]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#ConvertTo[ToGregorianCalendar010]

        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;
        import java.util.TimeZone;
        import java.util.Locale;

        class test {

            public static void main(String [] args) throws Exception {
                DatatypeFactory df = DatatypeFactory.newInstance();
                XMLGregorianCalendar calendar
                    = df.newXMLGregorianCalendar("2004-05-19T12:00:00+06:00");
                calendar.toGregorianCalendar(TimeZone.getDefault()
                                           , Locale.getDefault(), calendar);
                System.out.println("Passed. 1");
                calendar.toGregorianCalendar(TimeZone.getDefault()
                                           , Locale.getDefault(), null);
                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. 1
        Exception in thread "main" java.lang.NullPointerException
                at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.toGregorianCalendar(XMLGregorianCalendarImpl.java:2566)
                at test.main(test.java:15)
        ----------------------------------------------------

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

          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: