-
Bug
-
Resolution: Fixed
-
P2
-
6.0, 7.0.0_01, 1.3.0, 5.0, 8, 9
Name: ooR10006 Date: 07/22/2004
The following method of the class javax.xml.datatype.Duration
public abstract int compare(Duration duration)
does not detect INDETERMINATE order relation. It returns either LESSER, EQUAL or
GREATER for incomparable durations.
According to the XML Schema 1.0 Part 2 (Section 3.2.6.2, Order relation on duration)
the ?order-relation? on duration is a partial order since there is no determinate
relationship between certain durations such as one month (P1M) and 30 days (P30D).
The method (see test below) returns incorrect results for such pairs of values.
For instance, the LESSER is returned for 'P1M' and P30D'.
The bug is found in jdk15-b57 and is not reproducible with jdk15-b55.
The bug was not revealed in jdk15-b56 due to another bug
5062008 javax.xml.datatype.Duration.compare throws NPE if second is undefined
The bug affects the following new JCK 1.5 tests:
api/javax_xml/datatype/Duration/index.html#Duration[Compare001] 5062008 placeholder
api/javax_xml/datatype/Duration/index.html#Duration[Equals001] 5062008 placeholder
api/javax_xml/datatype/Duration/index.html#Duration[IsLongerThan001] 5062008 placeholder
api/javax_xml/datatype/Duration/index.html#Duration[IsShorterThan001]
To reproduce the bug compile and run the following code as shown in the log below.
--------------------------- test.java
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
class test {
static final String [][] partialOrder = { // partialOrder
{"P1Y", "<>", "P365D"},
{"P1Y", "<>", "P366D"},
{"P1M", "<>", "P28D"},
{"P1M", "<>", "P29D"},
{"P1M", "<>", "P30D"},
{"P1M", "<>", "P31D"},
{"P5M", "<>", "P150D"},
{"P5M", "<>", "P151D"},
{"P5M", "<>", "P152D"},
{"P5M", "<>", "P153D"},
{"PT2419200S", "<>", "P1M"},
{"PT2678400S", "<>", "P1M"},
{"PT31536000S", "<>", "P1Y"},
{"PT31622400S", "<>", "P1Y"},
{"PT525600M", "<>", "P1Y"},
{"PT527040M", "<>", "P1Y"},
{"PT8760H", "<>", "P1Y"},
{"PT8784H", "<>", "P1Y"},
{"P365D", "<>", "P1Y"},
}; // end of partialOrder
public static String cmp2str(int cmp) {
return cmp == DatatypeConstants.LESSER ? "LESSER"
: cmp == DatatypeConstants.GREATER ? "GREATER"
: cmp == DatatypeConstants.EQUAL ? "EQUAL"
: cmp == DatatypeConstants.INDETERMINATE ? "INDETERMINATE"
: "UNDEFINED";
}
public static void main(String [] args) throws Exception {
DatatypeFactory df = DatatypeFactory.newInstance();
String status = "Passed";
for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
int cmp = duration1.compare(duration2);
int expected = ">".equals(partialOrder[valueIndex][1])
? DatatypeConstants.GREATER
: "<".equals(partialOrder[valueIndex][1])
? DatatypeConstants.LESSER
: "==".equals(partialOrder[valueIndex][1])
? DatatypeConstants.EQUAL
: DatatypeConstants.INDETERMINATE;
if (cmp != expected) {
status = "Failed";
System.out.println("returned " + cmp2str(cmp)
+ " for durations \'" + duration1 + "\' and "
+ duration2 + "\', but expected " + cmp2str(expected));
}
}
System.out.println(status + ".");
}
}
-------------------------------------
--------------------------------- log
$javac test.java && java -showversion -cp . test
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b58)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b58, mixed mode)
returned EQUAL for durations 'P1Y' and P365D', but expected INDETERMINATE
returned LESSER for durations 'P1Y' and P366D', but expected INDETERMINATE
returned EQUAL for durations 'P1M' and P28D', but expected INDETERMINATE
returned LESSER for durations 'P1M' and P29D', but expected INDETERMINATE
returned LESSER for durations 'P1M' and P30D', but expected INDETERMINATE
returned LESSER for durations 'P1M' and P31D', but expected INDETERMINATE
returned EQUAL for durations 'P5M' and P150D', but expected INDETERMINATE
returned LESSER for durations 'P5M' and P151D', but expected INDETERMINATE
returned LESSER for durations 'P5M' and P152D', but expected INDETERMINATE
returned LESSER for durations 'P5M' and P153D', but expected INDETERMINATE
returned EQUAL for durations 'PT2419200S' and P1M', but expected INDETERMINATE
returned GREATER for durations 'PT2678400S' and P1M', but expected INDETERMINATE
returned EQUAL for durations 'PT31536000S' and P1Y', but expected INDETERMINATE
returned GREATER for durations 'PT31622400S' and P1Y', but expected INDETERMINATE
returned EQUAL for durations 'PT525600M' and P1Y', but expected INDETERMINATE
returned GREATER for durations 'PT527040M' and P1Y', but expected INDETERMINATE
returned EQUAL for durations 'PT8760H' and P1Y', but expected INDETERMINATE
returned GREATER for durations 'PT8784H' and P1Y', but expected INDETERMINATE
returned EQUAL for durations 'P365D' and P1Y', but expected INDETERMINATE
Failed.
-------------------------------------
======================================================================
###@###.### 2004-07-28
The following method of the class javax.xml.datatype.Duration
public abstract int compare(Duration duration)
does not detect INDETERMINATE order relation. It returns either LESSER, EQUAL or
GREATER for incomparable durations.
According to the XML Schema 1.0 Part 2 (Section 3.2.6.2, Order relation on duration)
the ?order-relation? on duration is a partial order since there is no determinate
relationship between certain durations such as one month (P1M) and 30 days (P30D).
The method (see test below) returns incorrect results for such pairs of values.
For instance, the LESSER is returned for 'P1M' and P30D'.
The bug is found in jdk15-b57 and is not reproducible with jdk15-b55.
The bug was not revealed in jdk15-b56 due to another bug
5062008 javax.xml.datatype.Duration.compare throws NPE if second is undefined
The bug affects the following new JCK 1.5 tests:
api/javax_xml/datatype/Duration/index.html#Duration[Compare001] 5062008 placeholder
api/javax_xml/datatype/Duration/index.html#Duration[Equals001] 5062008 placeholder
api/javax_xml/datatype/Duration/index.html#Duration[IsLongerThan001] 5062008 placeholder
api/javax_xml/datatype/Duration/index.html#Duration[IsShorterThan001]
To reproduce the bug compile and run the following code as shown in the log below.
--------------------------- test.java
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
class test {
static final String [][] partialOrder = { // partialOrder
{"P1Y", "<>", "P365D"},
{"P1Y", "<>", "P366D"},
{"P1M", "<>", "P28D"},
{"P1M", "<>", "P29D"},
{"P1M", "<>", "P30D"},
{"P1M", "<>", "P31D"},
{"P5M", "<>", "P150D"},
{"P5M", "<>", "P151D"},
{"P5M", "<>", "P152D"},
{"P5M", "<>", "P153D"},
{"PT2419200S", "<>", "P1M"},
{"PT2678400S", "<>", "P1M"},
{"PT31536000S", "<>", "P1Y"},
{"PT31622400S", "<>", "P1Y"},
{"PT525600M", "<>", "P1Y"},
{"PT527040M", "<>", "P1Y"},
{"PT8760H", "<>", "P1Y"},
{"PT8784H", "<>", "P1Y"},
{"P365D", "<>", "P1Y"},
}; // end of partialOrder
public static String cmp2str(int cmp) {
return cmp == DatatypeConstants.LESSER ? "LESSER"
: cmp == DatatypeConstants.GREATER ? "GREATER"
: cmp == DatatypeConstants.EQUAL ? "EQUAL"
: cmp == DatatypeConstants.INDETERMINATE ? "INDETERMINATE"
: "UNDEFINED";
}
public static void main(String [] args) throws Exception {
DatatypeFactory df = DatatypeFactory.newInstance();
String status = "Passed";
for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
int cmp = duration1.compare(duration2);
int expected = ">".equals(partialOrder[valueIndex][1])
? DatatypeConstants.GREATER
: "<".equals(partialOrder[valueIndex][1])
? DatatypeConstants.LESSER
: "==".equals(partialOrder[valueIndex][1])
? DatatypeConstants.EQUAL
: DatatypeConstants.INDETERMINATE;
if (cmp != expected) {
status = "Failed";
System.out.println("returned " + cmp2str(cmp)
+ " for durations \'" + duration1 + "\' and "
+ duration2 + "\', but expected " + cmp2str(expected));
}
}
System.out.println(status + ".");
}
}
-------------------------------------
--------------------------------- log
$javac test.java && java -showversion -cp . test
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b58)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b58, mixed mode)
returned EQUAL for durations 'P1Y' and P365D', but expected INDETERMINATE
returned LESSER for durations 'P1Y' and P366D', but expected INDETERMINATE
returned EQUAL for durations 'P1M' and P28D', but expected INDETERMINATE
returned LESSER for durations 'P1M' and P29D', but expected INDETERMINATE
returned LESSER for durations 'P1M' and P30D', but expected INDETERMINATE
returned LESSER for durations 'P1M' and P31D', but expected INDETERMINATE
returned EQUAL for durations 'P5M' and P150D', but expected INDETERMINATE
returned LESSER for durations 'P5M' and P151D', but expected INDETERMINATE
returned LESSER for durations 'P5M' and P152D', but expected INDETERMINATE
returned LESSER for durations 'P5M' and P153D', but expected INDETERMINATE
returned EQUAL for durations 'PT2419200S' and P1M', but expected INDETERMINATE
returned GREATER for durations 'PT2678400S' and P1M', but expected INDETERMINATE
returned EQUAL for durations 'PT31536000S' and P1Y', but expected INDETERMINATE
returned GREATER for durations 'PT31622400S' and P1Y', but expected INDETERMINATE
returned EQUAL for durations 'PT525600M' and P1Y', but expected INDETERMINATE
returned GREATER for durations 'PT527040M' and P1Y', but expected INDETERMINATE
returned EQUAL for durations 'PT8760H' and P1Y', but expected INDETERMINATE
returned GREATER for durations 'PT8784H' and P1Y', but expected INDETERMINATE
returned EQUAL for durations 'P365D' and P1Y', but expected INDETERMINATE
Failed.
-------------------------------------
======================================================================
###@###.### 2004-07-28