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

XMLGregorianCalendar constructor sets date incorrectly

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b35
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Name: erR10175 Date: 11/14/2003


       
        The following constructors of the class javax.xml.datatype.XMLGregorianCalendar
        
      public XMLGregorianCalendar(int year, int month, int date)
      public XMLGregorianCalendar(int year, int month, int date, int hour, int minute)
      public XMLGregorianCalendar(int year, int month, int date, int hour, int minute, second)

      change a given date in case when the given date is in the range between October 4, 1582
      and October 15, 1582.

      The dates in that range are invalid for class GregorianCalendar with default
      value of the cutover date, because October 4, 1582 (Julian) was followed
      by October 15, 1582 (Gregorian) (for details see the description of
      the class GregorianCalendar). But those dates are valid for XMLGregorianCalendar
      which implements plain model of the Gregorian calendar (see XML Schema 1.0 spec).

      In the test below, the date 'October 14, 1582' is used to create
      an XMLGregorianCalendar, but the new calendar returns field values of
      the date 'October 24, 1582'.
       
      This bug affects new tests in JCK 1.5
         api/javax_xml/datatype/Duration/index.html#DurationTests[AddTo001]
         api/javax_xml/datatype/Duration/index.html#DurationTests[AddTo004]

      The bug is found in jdk1.5.0/beta/b28.
      The bug is not reproducible in jdk1.5.0/beta/b26.

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

      public class test {

          static final int [][] values = {
              {2000, 1, 28},
              {2000, 1, 29}, // leap year
              {1, 0, 1},
              {1582, 9, 3}, // the day before
              {1582, 9, 4}, // the last day of Julian calendar
              {1582, 9, 5}, // the next day
              {1582, 9, 14}, // the day in between
              {1582, 9, 15}, // the first day of Gregorian calendar
              {1582, 9, 16}, // the next day
              {1969, 11, 31},
              {1970, 0, 1},
          };

          public static void main(String [] args) {
              StringBuffer result = new StringBuffer();
              for (int i = values.length; --i >= 0; ) {
                  XMLGregorianCalendar calendar =
                      new XMLGregorianCalendar(values[i][0], values[i][1], values[i][2]);

                  int year = calendar.get(Calendar.YEAR);
                  int month = calendar.get(Calendar.MONTH);
                  int day = calendar.get(Calendar.DAY_OF_MONTH);
                  if (year != values[i][0]
                   || month != values[i][1]
                   || day != values[i][2]) {
                      result.append("\ndate fields were set to "
                                  + year + "/" + (month+1) + "/" + day
                                  + ", expected " + values[i][0] + "/"
                                  + (values[i][1]+1) + "/" + values[i][2]);
                  }
              }
              
              if (result.length() >0) {
                  System.out.println("Failed: " + result);
              } else {
                  System.out.println("OK");
              }
          }
      }
      ----------------------------------------------------

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

      Failed:
      date fields were set to 1582/10/24, expected 1582/10/14
      date fields were set to 1582/10/15, expected 1582/10/5
      ----------------------------------------------------

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

        Attachments

          Activity

            People

            Assignee:
            jfialli Joe Fialli
            Reporter:
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: