FULL PRODUCT VERSION :
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
The conversion from XmlGregoriaCalendar to GregoriaCalendar can result in incorrect timezone set if the original object has a timezone with the minutes set greter than 0 and less than 10.
The result is:
Original String in XML Resulting Gregorian Calendar
2017-01-09T18:00:00.000+01:01 09-GEN-17 18:00:00,000000000 +11:00
2017-01-09T18:00:00.000+01:02 09-GEN-17 18:00:00,000000000 +12:00
2017-01-09T18:00:00.000+01:03 09-GEN-17 18:00:00,000000000 +13:00
2017-01-09T18:00:00.000+01:04 09-GEN-17 18:00:00,000000000 +14:00
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
GregorianCalendar c = new GregorianCalendar(2017, 0, 9, 18, 0, 0);
c.setTimeZone( TimeZone.getTimeZone( "GMT+01:01" ) );
XMLGregorianCalendar c2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
c2.setTimezone( (1*60)+1 ); // sets the timezone in minutes
System.out.println( "c2.toGregorianCalendar().getTimeZone() = " + c2.toGregorianCalendar().getTimeZone() );
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The correct timezone is GMT+1:01, not GMT+11:00
ACTUAL -
c2.toGregorianCalendar().getTimeZone() = sun.util.calendar.ZoneInfo[id="GMT+11:00",offset=39600000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message or log
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
GregorianCalendar c = new GregorianCalendar(2017, 0, 9, 18, 0, 0);
c.setTimeZone( TimeZone.getTimeZone( "GMT+01:01" ) );
XMLGregorianCalendar c2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
c2.setTimezone( (1*60)+1 ); // sets the timezone in minutes
System.out.println( "c2.toGregorianCalendar().getTimeZone() = " + c2.toGregorianCalendar().getTimeZone() );
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
A possible workaround is to avoid the method setTimezone of the XMLGregorianCalendar and use the setTimeZone of the GregoriaCalendar after conversion.
I tracked down the error in method com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl#getTimeZone
An extract:
StringBuffer customTimezoneId = new StringBuffer(8);
customTimezoneId.append("GMT");
customTimezoneId.append(sign);
customTimezoneId.append(hour);
if (minutes != 0) {
customTimezoneId.append(minutes);
}
If minutes is not zero is appended without the ':' separator.
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
The conversion from XmlGregoriaCalendar to GregoriaCalendar can result in incorrect timezone set if the original object has a timezone with the minutes set greter than 0 and less than 10.
The result is:
Original String in XML Resulting Gregorian Calendar
2017-01-09T18:00:00.000+01:01 09-GEN-17 18:00:00,000000000 +11:00
2017-01-09T18:00:00.000+01:02 09-GEN-17 18:00:00,000000000 +12:00
2017-01-09T18:00:00.000+01:03 09-GEN-17 18:00:00,000000000 +13:00
2017-01-09T18:00:00.000+01:04 09-GEN-17 18:00:00,000000000 +14:00
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
GregorianCalendar c = new GregorianCalendar(2017, 0, 9, 18, 0, 0);
c.setTimeZone( TimeZone.getTimeZone( "GMT+01:01" ) );
XMLGregorianCalendar c2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
c2.setTimezone( (1*60)+1 ); // sets the timezone in minutes
System.out.println( "c2.toGregorianCalendar().getTimeZone() = " + c2.toGregorianCalendar().getTimeZone() );
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The correct timezone is GMT+1:01, not GMT+11:00
ACTUAL -
c2.toGregorianCalendar().getTimeZone() = sun.util.calendar.ZoneInfo[id="GMT+11:00",offset=39600000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message or log
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
GregorianCalendar c = new GregorianCalendar(2017, 0, 9, 18, 0, 0);
c.setTimeZone( TimeZone.getTimeZone( "GMT+01:01" ) );
XMLGregorianCalendar c2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
c2.setTimezone( (1*60)+1 ); // sets the timezone in minutes
System.out.println( "c2.toGregorianCalendar().getTimeZone() = " + c2.toGregorianCalendar().getTimeZone() );
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
A possible workaround is to avoid the method setTimezone of the XMLGregorianCalendar and use the setTimeZone of the GregoriaCalendar after conversion.
I tracked down the error in method com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl#getTimeZone
An extract:
StringBuffer customTimezoneId = new StringBuffer(8);
customTimezoneId.append("GMT");
customTimezoneId.append(sign);
customTimezoneId.append(hour);
if (minutes != 0) {
customTimezoneId.append(minutes);
}
If minutes is not zero is appended without the ':' separator.