JDK-7042647 : XMLGregorianCalendar: incorrect conversion in GregorianCalendar
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-05-06
  • Updated: 2017-02-11
  • Resolved: 2012-02-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7u4 b07Fixed
Related Reports
Relates :  
Description
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

Comments
EVALUATION Patch committed into jaxp 1.4.5 update 1.
07-09-2011

SUGGESTED FIX The following specification should be corrected: 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 XMLGregorianCalendarImp.java should be altered.
06-05-2011

EVALUATION The realization of the toGregorianCalendar() method should be altered according to CCC: 4700857: RFE: separating user locale and user interface locale. The method use default locale as: ---code snippet of XMLGregorianCalendarImp.java--- public java.util.GregorianCalendar toGregorianCalendar() { ..... Locale locale = Locale.getDefault(); result = new GregorianCalendar(tz, locale); ...... ---------------------------------------------------- This locale differs from the locale (Locale.getDefault(Locale.Category.FORMAT)) that is used in the method as follows: public static Calendar getInstance() { Calendar cal = createCalendar(TimeZone.getDefaultRef(), Locale.getDefault(Locale.Category.FORMAT)); cal.sharedZone = true; return cal; }
06-05-2011