Hi,

We have recently been experiencing issues deserialising XML with specific time 
zones. This only seems to be occurring on Windows where the time zone does not 
have an Id that is in the available list of Ids. It seems this is caused by 
Windows not using the Olson time zone database.


For example, when setting the system time zone to GMT-12:00 and calling 
TimeZone.getDefault().getID() the JRE will return "GMT-12:00". Joda time knows 
about this and if you try and use this to convert to a Joda DateTimeZone it 
will strip of the "GMT" prefix and return a time zone with Id of "-12:00".


The problem seems to be in 
com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter.fromString(String)?.
 This has the following code:

...
String timeZoneID = TimeZone.getDefault().getID();
for (int i = 0; i < formattersNoUTC.length; i++ ) {
try {
DateTimeFormatter formatter = 
formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID));
...
} ...
}
...

This code is getting the time zone Id from the JRE and then passing this to 
DateTimeZone.forID to convert to a Joda time zone. This doesn't work when the 
time zone Id is not in the available list of Ids. There is an invalid 
assumption that the same time zone Id from the JRE can be used to get the Joda 
time zone.

There is actually no need to even use the Id here, the code could simply be:
...
final DateTimeZone dtz = DateTimeZone.getDefault();
for (int i = 0; i < formattersNoUTC.length; i++ ) {
try {
DateTimeFormatter formatter = formattersNoUTC[i].withZone(dtz);
...
} ...
}
...

This ignores the problem entirely and uses the time zone reported by Joda 
directly.

Reply via email to