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

XMLGregorianCalendar.toGregorianCalendar returns incorrect value for UTC+2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8u161
    • xml
    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.8.0_161"
      Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux laptop 4.4.0-112-generic #135~14.04.1-Ubuntu SMP Tue Jan 23 20:41:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The unit test below fails with the above java version, but passes with this version:

      openjdk version "1.8.0_141"
      OpenJDK Runtime Environment (build 1.8.0_141-8u141-b15-3~14.04-b15)
      OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode)

      The problem might be in the XMLGregorianCalendar.toGregorianCalendar() call or in GregorianCalendar.getTimeInMillis() and I don't know which of the two versions of the JDK is at fault, but it should be relatively easy to investigate further.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run unit test.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should pass.
      ACTUAL -
      Fails.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      CalendarHelperTest.testFromXmlGregorianCalendar:49 expected:<1399551732104> but was:<1399558812104>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      @Test
          public void testFromXmlGregorianCalendar() throws DatatypeConfigurationException {
              XMLGregorianCalendar cal =
                      DatatypeFactory.newInstance().newXMLGregorianCalendar();
              // UTC + 2 = CET daylight savings
              cal.setTimezone(2);
              
              cal.setYear(2014);
              cal.setMonth(5);
              cal.setDay(8);
              
              cal.setHour(14);
              cal.setMinute(22);
              cal.setSecond(12);
              cal.setMillisecond(104);
              
              long expected = 1399551732104L;
              long actual = cal.toGregorianCalendar().getTimeInMillis();
              assertEquals(expected, actual);
          }

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

      CUSTOMER SUBMITTED WORKAROUND :
      use different JDK

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: