Title: [2072] trunk: ISO8601GregorianCalendarConverter creates Calendar instance with wrong Locale in Java 7 if the Locale for the LocaleCategory.FORMAT is different to the global default Locale (XSTR-740).
Revision
2072
Author
joehni
Date
2013-06-21 14:52:54 -0500 (Fri, 21 Jun 2013)

Log Message

ISO8601GregorianCalendarConverter creates Calendar instance with wrong Locale in Java 7 if the Locale for the LocaleCategory.FORMAT is different to the global default Locale (XSTR-740).

Modified Paths

Added Paths

Diff

Modified: trunk/xstream/pom.xml (2071 => 2072)


--- trunk/xstream/pom.xml	2013-06-20 21:15:43 UTC (rev 2071)
+++ trunk/xstream/pom.xml	2013-06-21 19:52:54 UTC (rev 2072)
@@ -211,6 +211,25 @@
 
   <profiles>
     <profile>
+      <id>jdk15-16</id>
+      <activation>
+        <jdk>[1.5,1.7)</jdk>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <configuration>
+              <testExcludes>
+                <exclude>**/extended/*17Test*</exclude>
+              </testExcludes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
       <id>jdk15-ge</id>
       <activation>
         <jdk>[1.5,)</jdk>

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.java (2071 => 2072)


--- trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.java	2013-06-20 21:15:43 UTC (rev 2071)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.java	2013-06-21 19:52:54 UTC (rev 2072)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2005 Joe Walnes.
- * Copyright (C) 2006, 2007, 2011 XStream Committers.
+ * Copyright (C) 2006, 2007, 2011, 2013 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -21,7 +21,6 @@
 
 import java.util.Calendar;
 import java.util.GregorianCalendar;
-import java.util.Locale;
 import java.util.TimeZone;
 
 
@@ -81,7 +80,7 @@
         ISODateTimeFormat.weekyearWeek(),
         ISODateTimeFormat.weekyearWeekDay()
     };
-
+    
     public boolean canConvert(Class type) {
         return type.equals(GregorianCalendar.class);
     }
@@ -91,7 +90,7 @@
             DateTimeFormatter formatter = formattersUTC[i];
             try {
                 DateTime dt = formatter.parseDateTime(str);
-                Calendar calendar = dt.toCalendar(Locale.getDefault());
+                Calendar calendar = dt.toGregorianCalendar();
                 calendar.setTimeZone(TimeZone.getDefault());
                 return calendar;
             } catch (IllegalArgumentException e) {
@@ -103,7 +102,7 @@
             try {
                 DateTimeFormatter formatter = formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID));
                 DateTime dt = formatter.parseDateTime(str);
-                Calendar calendar = dt.toCalendar(Locale.getDefault());
+                Calendar calendar = dt.toGregorianCalendar();
                 calendar.setTimeZone(TimeZone.getDefault());
                 return calendar;
             } catch (IllegalArgumentException e) {

Added: trunk/xstream/src/test/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter17Test.java (0 => 2072)


--- trunk/xstream/src/test/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter17Test.java	                        (rev 0)
+++ trunk/xstream/src/test/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter17Test.java	2013-06-21 19:52:54 UTC (rev 2072)
@@ -0,0 +1,55 @@
+/*
+ * 2013 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ * 
+ * Created on 21. June 2013 by Joerg Schaible
+ */
+package com.thoughtworks.xstream.converters.extended;
+
+import com.thoughtworks.xstream.testutil.TimeZoneChanger;
+
+import junit.framework.TestCase;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+
+public class ISO8601GregorianCalendarConverter17Test extends TestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        // Ensure that this test always run as if it were in the timezone of Panama.
+        // This prevents failures when running the tests in different zones.
+        // Note: 'America/Panama' has no relevance - it was just a randomly chosen zone.
+        TimeZoneChanger.change("America/Panama");
+    }
+
+    protected void tearDown() throws Exception {
+        TimeZoneChanger.reset();
+        super.tearDown();
+    }
+    
+    public void testCanLoadTimeWithDefaultDifferentLocaleForFormat() {
+        final ISO8601GregorianCalendarConverter converter = new ISO8601GregorianCalendarConverter();
+
+        Locale defaultLocale = Locale.getDefault();
+        Locale defaultLocaleForFormat = Locale.getDefault(Locale.Category.FORMAT);
+        try {
+            Locale.setDefault(Locale.US);
+            Locale.setDefault(Locale.Category.FORMAT, Locale.GERMANY);
+            Calendar in = new GregorianCalendar(2013, Calendar.JUNE, 17, 16, 0, 0);
+            
+            String converterXML =  converter.toString(in);
+            Calendar out = (Calendar) converter.fromString(converterXML);
+            assertEquals(in, out);
+        } finally {
+            Locale.setDefault(defaultLocale);
+            Locale.setDefault(defaultLocaleForFormat);
+        }
+    }
+}
Property changes on: trunk/xstream/src/test/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter17Test.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/xstream-distribution/src/content/changes.html (2071 => 2072)


--- trunk/xstream-distribution/src/content/changes.html	2013-06-20 21:15:43 UTC (rev 2071)
+++ trunk/xstream-distribution/src/content/changes.html	2013-06-21 19:52:54 UTC (rev 2072)
@@ -69,6 +69,8 @@
     	<li>JIRA:XSTR-736: XStream.unmarshal may throw NPE is version info of manifest is missing.</li>
     	<li>JIRA:XSTR-733: Implicit elements that match multiple defined implicit collections will be assigned to the
     	map with the nearest matching element type.</li>
+    	<li>JIRA:XSTR-740: ISO8601GregorianCalendarConverter creates Calendar instance with wrong Locale in Java 7 if
+    	the Locale for the LocaleCategory.FORMAT is different to the global default Locale.</li>
     </ul>
 
     <h2>API changes</h2>

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to