Using java.util.Calendar with XmlBeans properties causes Calendar object to be
modified
---------------------------------------------------------------------------------------
Key: XMLBEANS-343
URL: https://issues.apache.org/jira/browse/XMLBEANS-343
Project: XMLBeans
Issue Type: Bug
Affects Versions: Version 2.3
Environment: Apache XmlBeans version 2.3.0-r540734
J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20060504 (JIT enabled)
J9VM - 20060501_06428_lHdSMR
JIT - 20060428_1800_r8
GC - 20060501_AA
Reporter: J Blaufuss
Priority: Minor
A java.util.Calendar object is modified after being passed to a XmlBeans object
setter method. Specifically, if a field is cleared on the Calendar before
being passed in, it may be uncleared by the setter. I believe this behavior is
incorrect, as my expectation is that XmlBeans will not tamper with the data
that it's given. For an example, see below.
The effect of this is if your schema specifies an element with type xs:date,
but for whatever reason you cannot or do not want to have the time zone appear
in your xml, you have to explicitly clear the ZONE_OFFSET field on the calendar
*each time* before you use it to set an XmlBean object property. Otherwise,
the second time you use a calendar to set a date it will appear with a timezone
in your xml.
**** schema for the example bean ****
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="date" type="xs:date"/>
</xs:schema>
**** example code ****
package test;
import java.util.Calendar;
import noNamespace.DateDocument;
public class Test2
{
public static void main(String args[])
{
// create a new calendar
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 1844);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.DAY_OF_MONTH, 1);
// clear time zone from calendar
calendar.clear(Calendar.ZONE_OFFSET);
// store the before status of the ZONE_OFFSET field
// before == false
boolean before = calendar.isSet(Calendar.ZONE_OFFSET);
// create bean & set a element with type xs:date with calendar
DateDocument dateDoc = DateDocument.Factory.newInstance();
dateDoc.setDate(calendar);
// store the after status of the ZONE_OFFSET field
// I expect both before & after to equal false,
// but after == true in this case
boolean after = calendar.isSet(Calendar.ZONE_OFFSET);
if (before != after)
{
System.out
.println("Change detected in
ZONE_OFFSET field: before:"
+ before + " after:" +
after);
}
else
{
System.out.println("No change detected.");
}
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]