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

XMLGregorianCalendar: parse() doesn't throw IAE for '1999-02-29'

    XMLWordPrintable

    Details

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

      Backports

        Description

        Name: erR10175 Date: 03/31/2004



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

        public static XMLGregorianCalendar parse(String lexicalRepresentation)

        does not throw IllegalArgumentException in case when the date '1999-02-29'
        is parsed.

        The javadoc of the method reads:
        "
          Returns a non-null valid XMLGregorianCalendar object that holds
          the value indicated by the lexicalRepresentation parameter.
          ...
          Throws:
            IllegalArgumentException - If the given string does not conform to
                                       the aforementioned specification.
        "
        So, if the method returns a value, the value must be valid (i.e. method
        isValid() should return true), otherwise IllegalArgumentException should
        be thrown. As the year 1999 is not leap the date '1999-02-29' is not
        valid and IllegalArgumentException should be thrown.

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

            api/javax_xml/datatype/XMLGregorianCalendar/index.html#Parse[Parse003]

        The bug is found in jdk1.5.0/beta2/b44. The test is in KFL with the RI bug

        4972888 XMLGregorianCalendar.parse throws StringIndexOutOfBoundsException

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

        class test {

            public static void main(String [] args) {
                try {
                    XMLGregorianCalendar calendar
                        = XMLGregorianCalendar.parse("1999-02-29");
                    if (!calendar.isValid()) {
                        System.out.println("Failed: isValid() returns false");
                    }
                    System.out.println("Failed: IllegalArgumentException is not thrown");
                } catch (IllegalArgumentException e) {
                    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)

        Failed: isValid() returns false
        Failed: IllegalArgumentException is not thrown
        ----------------------------------------------------

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

          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: