Issue Details (XML | Word | Printable)

Key: JAXP-73
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: gturner
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

Problem unmarshalling duration-type fields containing whitespace

Created: 15/Mar/11 10:48 AM   Updated: 28/Jun/12 02:25 PM
Component/s: None
Affects Version/s: current
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive (2 kB) 08/Apr/11 11:13 AM - gturner


Operating System: Windows XP
Platform: All

Issuezilla Id: 590
Participants: gturner, Iaroslav Savytskyi and Martin Grebac

 Description  « Hide

The following problem could be observed in Jaxb 2.1:

Having an XML schema that defines the following type:
<element name="PublishedStartTime" type="dateTime" minOccurs="0"/>

and an having an XML instance document with the following entry:

... i.e. with trailing and leading whitespaces, will result in an an
unmarshalled PublishedStartTime of null instead of the expected date and time.

The problem does not occur, if the entry in the XML instance document looks as


... i.e. there are no leading and trailing whitespaces.
The Jaxb-classes generated with XJC use XMLGregorianCalendar as the data type
holding dateTime types.

The problem seems to be that the XMLGregorianCalendar / DatatypeFactory does not
support input strings with leading and trailing whitespaces as documented in
Additionally it seems that the Jaxb2.1 runtime does not remove leading and
trailing whitespaces from dateTime entries.

We believe this is a bug, since either XMLGregorianCalendar should support
leading and trailing whitespaces, or Jaxb2.1 RI should remove leading and
trailing whitepsaces for dateTime entries. Otherwise, another JavaType than
XMLGregorianCalendar should be used as default type for xsd:dateTime types.

Best regards,

Hao and Florian

gturner added a comment - 15/Mar/11 10:55 AM


Sorry I used the JIRA "Clone" link from bug 590. I didn't realize it would copy the initial comment. Version number, environment, etc. are wrong too.

I am using 2.1.13 and am experiencing the same effect on duration types.



System.out.println(object.getStartTime()); // => 2006-12-05T09:36:48.596-08:00; Good! Bug 590 fixed.
System.out.println(object.getExpireTime()); // => null; Bad! Similar to bug 590.

Martin Grebac added a comment - 08/Apr/11 01:39 AM

Thanks for filing this - would you please also attach a simple testcase?

gturner added a comment - 08/Apr/11 09:52 AM

Hi Martin, I was going to write a testcase with the jaxb source, but it appears that jaxb-unit is not open source - - is this still true?

Martin Grebac added a comment - 08/Apr/11 10:28 AM

Yes, still true. You don't need to follow any guidelines/layout/whatever - anything I can execute is fine - just so that it contains the xsd/xml and the code you use.

gturner added a comment - 08/Apr/11 11:13 AM

Attached is a testcase, a self-contained project using Ant, not JUnit or anything, may have lots of trouble running with dll-hell that is Xerces and JAXB inclusion in JRE. Here are the relevant bits:


<xs:element name="document">
<xs:element name="duration" type="xs:duration" maxOccurs="unbounded"/>


<document xmlns="urn:test">
<duration> PT1H</duration>
<duration>PT1H </duration>
<duration> PT1H </duration>

for (Duration duration : doc.getDuration())
if (duration != null)
System.out.println("Got duration " + duration);
System.err.println("Got NULL duration!");

Ant output:

[java] Got duration PT1H
[java] Got NULL duration!
[java] Got NULL duration!
[java] Got NULL duration!
[java] Got NULL duration!

Iaroslav Savytskyi added a comment - 28/Jun/12 02:23 PM

Hi, Joe,

I think this is JAXP bug. As I see from the spec for the duration type it should do "whiteSpace = collapse (fixed)".