United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7042647 XMLGregorianCalendar: incorrect conversion in GregorianCalendar
7042647 : XMLGregorianCalendar: incorrect conversion in GregorianCalendar

Details
Type:
Bug
Submit Date:
2011-05-06
Status:
Closed
Updated Date:
2012-09-28
Project Name:
JDK
Resolved Date:
2012-02-03
Component:
xml
OS:
generic
Sub-Component:
jaxp
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u4

Related Reports
Relates:

Sub Tasks

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.
                                     
2011-09-07
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.
                                     
2011-05-06
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;
    }
                                     
2011-05-06



Hardware and Software, Engineered to Work Together