Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8028363

XmlGregorianCalendarImpl.getTimeZone() bug when offset is less than 10 minutes

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 8u152
    • Component/s: xml
    • Labels:
    • Resolved In Build:
      b01
    • OS:
      linux

      Backports

        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();

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  snikandrova Svetlana Nikandrova (Inactive)
                  Reporter:
                  robm Robert Mckenna
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: