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

Incorrect treatment of xml dateTime elements with high resolution

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 6
    • xml
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      Microsoft Windows XP [Version 5.1.2600]
      (C) Copyright 1985-2001 Microsoft Corp.

      Z:\>java -version
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

      Z:\>

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional version 2002 Service Pack 2

      A DESCRIPTION OF THE PROBLEM :
      When unmarshalling the following fragment:

      <dateTime>2007-04-26T11:51:08.0000000Z</dateTime>

      we get a XMLGregorianCalendar object. If we invoke the toString() method on the object we get the following:

      2007-04-26T11:51:08E-7Z, which is not a properly formatted string.

      We get the same format error when marshalling the object, and unmarshalling that string gives null as a result.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The code:

      String s = DatatypeFactory.newInstance().newXMLGregorianCalendar("2007-04-26T11:51:08.0000000Z").toString();
      DatatypeFactory.newInstance().newXMLGregorianCalendar(s);

      Produces the following output:

      java.lang.IllegalArgumentException: 2007-04-26T11:51:08E-7Z
      at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(XMLGregorianCalendarImpl.java:2787)
      at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.<init>(XMLGregorianCalendarImpl.java:433)
      at com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(DatatypeFactoryImpl.java:230)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect that java would be able to handle a valid xml dataTime element correctly.
      ACTUAL -
      Our application was processing data correctly with xml-documents coming from a JAXB environment, but was unable to process similar data produced by an application developed within a Microsoft environment by another company.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      See above

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.xml.datatype.DatatypeConfigurationException;
      import javax.xml.datatype.DatatypeFactory;
      import javax.xml.datatype.XMLGregorianCalendar;

      public class Test {
          
          public static void main(String[] args) {
             try {
                     String s = DatatypeFactory.newInstance().newXMLGregorianCalendar(
                             "2007-04-26T11:51:08.0000000Z").toString();
                     System.out.println(s); //incorrect output
                     //incorrect output of s;
                     //thus, exception thrown when marshalling
                     DatatypeFactory.newInstance().newXMLGregorianCalendar(s);
              } catch (DatatypeConfigurationException ex) {
                  ex.printStackTrace();
              }
          }
      }



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

      CUSTOMER SUBMITTED WORKAROUND :
      As a workaround we use the setMillisecond(getMillisecond()) methods to round to the nearest millisecond.

          XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar("2007-04-26T11:51:08.0000000Z");
          calendar.setMillisecond(calendar.getMillisecond());
          String s = calendar.toString();
          DatatypeFactory.newInstance().newXMLGregorianCalendar(s);

            nwalshsunw Norman Walsh (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: