United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6937964 XML Duration do not conform to W3C specifications
JDK-6937964 : XML Duration do not conform to W3C specifications

Details
Type:
Bug
Submit Date:
2010-03-24
Status:
Closed
Updated Date:
2012-06-08
Project Name:
JDK
Resolved Date:
2010-07-22
Component:
xml
OS:
solaris_10
Sub-Component:
jaxp
CPU:
sparc
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u18
Fixed Versions:
6u20-rev (b09)

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
XML DURATIONS DO NOT CONFORM TO W3C SPECIFICATIONS (Oracle Bug 9477446 )
Expected output:
Answer should be in canonical form, i.e. 21 years, 3 months.
Actual output: 
20 years, 15 months.

This appears to be a bug in javax.xml.datatype.Duration or DatatypeFactory.

JDK: 6u18-b09 (latest)

/* test case */

import javax.xml.datatype.*;

public class Bug {
 public static void main(String[] args) throws DatatypeConfigurationException {
  DatatypeFactory dtf = DatatypeFactory.newInstance();
  Duration d = dtf.newDuration("P20Y15M");
  System.out.println(d.getYears()==21 ? "pass" : "fail");
 }
}

                                    

Comments
EVALUATION

The spec for Duration does not define a canonical lexical representation. Such operations would require presence of a calendar since some values, for example 60 days, are indeterminate.
                                     
2010-04-08
EVALUATION

I agree that the two subtypes have defined Canonical representation, and total order. However, the rules for subtypes can not be applied back to their base type. As in the W3C spec, Duration [1] does not define canonical representation.

That said, DatatypeFactory does have newDurationYearMonth and newDurationDayTime methods that are defined as the XQuery/XPath specs. I expected that a duration created with these methods would return normalized. Unfortunately, it did not in my test (Duration d0 = dtf.newDurationYearMonth("P20Y15M");). That gave me a second thought, and I think I might understand what you're expecting, that is, even with a general representation, the implementation could have been made smart enough to detect that the input conforms to a defined subtype and therefore behaves accordingly. Would this change cause regression? It's possible. But the newDurationYearMonth methods are wrong.

[1] http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#duration
                                     
2010-04-09
EVALUATION

As discussed previouly, durations created using newDurationYearMonth and newDurationDayTime methods should comply with the W3C specs as defined in the Java API document.

The impl for the base type (Duration) should be left as it is since there's risk of regression changing it (e.g. examine the input to determine if subtypes may be used).
                                     
2010-04-09



Hardware and Software, Engineered to Work Together