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

XMLGregorianCalendar.isValid() throws NPE if month==2 and year is undefined

    Details

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

      Backports

        Description

        Name: erR10175 Date: 05/04/2004



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

        public boolean isValid()

        throws NullPointerException for the valid XMLGregorianCalendar instance gMonth(FEBRUARY).

        The method is declared to throw no exceptions and is expected to return true for gMonth(FEBRUARY).
        So the sample (see below) should report "Passed: OK".

        The bug is found in jdk1.5.0/beta2/b49 because the RI calls isValid() when parsing "--02--".

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

          api/javax_xml/datatype/XMLGregorianCalendar/index.html#Compare[Compare001]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#Compare[Equals001]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDate001]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime001]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime004]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime006]

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

        class test {
            public static void main(String [] args) {
                XMLGregorianCalendar gMonth = XMLGregorianCalendar.parse("2000-02");
                gMonth.setYear(null);
                boolean valid = gMonth.isValid();
                if (valid) {
                    System.out.println("Passed: OK");
                } else {
                    System.out.println("Failed: isValid returned false for gMonth(--02--)");
                }
            }
        }
        -------------------------------------

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

        Exception in thread "main" java.lang.NullPointerException
                at javax.xml.datatype.XMLGregorianCalendar.maximumDayInMonthFor(XMLGregorianCalendar.java:2242)
                at javax.xml.datatype.XMLGregorianCalendar.isValid(XMLGregorianCalendar.java:1941)
                at test.main(test.java:7)
        -------------------------------------

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

          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: