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

XMLGregorianCalendar: incorrect conversion in GregorianCalendar

XMLWordPrintable

    • b07
    • generic
    • generic
    • Verified

      The following code snippet shows a defect in implementation of toGregorianCalendar()

         XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(1970, 1, 1, 0, 0, 0, 0, 0);
         GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
         int firstDayOfWeek = calendar.getFirstDayOfWeek();
         Calendar defaultCalendar = Calendar.getInstance();
         int defaultFirstDayOfWeek = defaultCalendar.getFirstDayOfWeek();
         if ( firstDayOfWeek != defaultFirstDayOfWeek) {
            return Status("Failed " + firstDayOfWeek + " != " + defaultFirstDayOfWeek);
         }

      --- Output: ----
       Failed 1 != 2
      ----------------
      It can be reproduced on Windows 7 en_US that has the following settings:
      Control Panel - All Control Panel Items - Region and Laguage
       Format:
           Format Russian (Russia)
       Location:
           Current location:
           Russia
          
      The API documentation for toGregorianCalendar states:

      public abstract GregorianCalendar toGregorianCalendar()
      ...
      To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.
          * Using timeZone value as defined above, create a new java.util.GregorianCalendar(timeZone,Locale.getDefault())
      ...

      The API documentation for getInstance states:

      public static Calendar getInstance()

      Gets a calendar using the default time zone and locale. The Calendar returned is based on the current time in the default time zone with the default locale.

      Thus desired result is FirstDayOfWeek of GregorianCalendar should be equal to the FirstDayOfWeek of Calendar

            joehw Joe Wang
            lkuskov Leonid Kuskov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: