You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "J Blaufuss (JIRA)" <xm...@xml.apache.org> on 2007/08/27 21:01:44 UTC

[jira] Created: (XMLBEANS-343) Using java.util.Calendar with XmlBeans properties causes Calendar object to be modified

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: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Commented: (XMLBEANS-343) Using java.util.Calendar with XmlBeans properties causes Calendar object to be modified

Posted by "Wing Yew Poon (JIRA)" <xm...@xml.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLBEANS-343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12523093 ] 

Wing Yew Poon commented on XMLBEANS-343:
----------------------------------------

XMLBeans does have to call get on the Calendar fields.

> 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
>         Attachments: dateElementSchema.xsd, Test2.java
>
>
> 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: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Updated: (XMLBEANS-343) Using java.util.Calendar with XmlBeans properties causes Calendar object to be modified

Posted by "J Blaufuss (JIRA)" <xm...@xml.apache.org>.
     [ https://issues.apache.org/jira/browse/XMLBEANS-343?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J Blaufuss updated XMLBEANS-343:
--------------------------------

    Attachment: dateElementSchema.xsd

Schema for bug example

> 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
>         Attachments: dateElementSchema.xsd
>
>
> 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: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Updated: (XMLBEANS-343) Using java.util.Calendar with XmlBeans properties causes Calendar object to be modified

Posted by "J Blaufuss (JIRA)" <xm...@xml.apache.org>.
     [ https://issues.apache.org/jira/browse/XMLBEANS-343?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J Blaufuss updated XMLBEANS-343:
--------------------------------

    Attachment: Test2.java

Code for bug example

> 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
>         Attachments: dateElementSchema.xsd, Test2.java
>
>
> 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: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Resolved: (XMLBEANS-343) Using java.util.Calendar with XmlBeans properties causes Calendar object to be modified

Posted by "Wing Yew Poon (JIRA)" <xm...@xml.apache.org>.
     [ https://issues.apache.org/jira/browse/XMLBEANS-343?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wing Yew Poon resolved XMLBEANS-343.
------------------------------------

    Resolution: Won't Fix

This is simply a limitation of the behavior of java.util.GregorianCalendar.
When you get a Calendar field, that action may cause it or other fields to be set, even if the fields were not previously set.
To see this for yourself, simply modify your test case as follows:
replace the lines

        // create bean & set a element with type xs:date with calendar
        DateDocument dateDoc = DateDocument.Factory.newInstance();
        dateDoc.setDate(calendar);

with the line

        System.out.println(calendar.get(Calendar.ZONE_OFFSET));

XMLBeans is not involved at all.
You will see that the field gets set to its default.


> 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
>         Attachments: dateElementSchema.xsd, Test2.java
>
>
> 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: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org