JDK-8028363 : XmlGregorianCalendarImpl.getTimeZone() bug when offset is less than 10 minutes
  • Type: Bug
  • Component: xml
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • Submitted: 2013-03-20
  • Updated: 2017-11-29
  • Resolved: 2016-07-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u152 b01Fixed
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_02 " 
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux <hostname> 2.6.32.46-0.3-xen #1 SMP 2011-09-29 17:49:31 +0200 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
issue with getting the timezone of an XMLGregorianCalendar when the offset is less than 10 minutes.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create an Instance of XMLGregorianCalendar with an time offset smaller than 10 minutes

for example offset of 5 min: 2012-10-01T05:06:07+00:05

2. call the function getTimeZone on the new created Object

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected Timezone ID is:

GMT+00:05
ACTUAL -
actual Result Timezone ID is:

GMT+05:00

ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

package TestCode;

import java.util.TimeZone;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

/**
 *
 * @author schreibe
 */
public class GetTimeZoneBug {
    
    public GetTimeZoneBug() {
    }
    
    public void showBug(String xmlTimestamp) {
        System.out.println( " showBug method was called with xmlTimestamp:  "  + xmlTimestamp);
    
        try {
            XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(xmlTimestamp);
            
            /*
             * The Bug appears inside of the getTimeZone function if the XMLGregorianCalendar was created with a offset less than 10 minutes.
             */
            TimeZone xmlTZ = xmlCal.getTimeZone(DatatypeConstants.FIELD_UNDEFINED);
            
            System.out.println( " timezone of xmlgregoriancalendar:  "  + xmlTZ.getID());
            
        } catch(DatatypeConfigurationException e) {
            System.out.println( " exception while creating xmlGregorianCalendar objec:  "  + e.getMessage());
        }
    }
    
    public static void main(String[] args) {
        GetTimeZoneBug gtzb = new GetTimeZoneBug();
        
        gtzb.showBug( " 2012-10-01T05:06:07+00:05 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:06 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:07 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:08 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:09 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:10 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:11 " );
        gtzb.showBug( " 2012-10-01T05:06:07+00:12 " );
        
        System.out.println( " 
just another example: " );
        
        gtzb.showBug( " 2012-10-01T05:06:07+02:01 " );
    }
            
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
a workaorund is to normalize the xmlGregorianCalendar before continue on processing it by calling

xmlCal.normalize();