Name: erR10175 Date: 12/25/2003
The following method of the class javax.xml.datatype.Duration
public static int compare(Duration lhs, Duration rhs)
throws IllegalArgumentException if the first duration is negative and
has non-zero day, hour, minute or second field specified (e.g. '-P1D',
'-P1DT1H')
Javadoc of the method does not specify any case when
IllegalArgumentException may be thrown, so it is a bug.
This bug affects new tests in JCK 1.5 (not integrated yet)
api/javax_xml/datatype/Duration/index.html#Add[Add001]
api/javax_xml/datatype/Duration/index.html#Ctor[Ctor003]
api/javax_xml/datatype/Duration/index.html#Negate[Negate001]
api/javax_xml/datatype/Duration/index.html#Subtract[Subtract001]
The bug is found in jdk1.5.0/beta/b32.
To reproduce the bug compile and run the following code as shown
in the log below:
------------------------------------------ test.java
import javax.xml.datatype.Duration;
public class test {
public static void main(String [] args) {
Duration d1 = new Duration("-P1D");
Duration d2 = new Duration("P1Y");
Duration.compare(d1,d2);
System.out.println("OK");
}
}
----------------------------------------------------
------------------------------------------------ log
$javac test.java && java -cp . -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)
Exception in thread "main" java.lang.IllegalArgumentException: invalid value for setMonth(int)
at javax.xml.datatype.XMLGregorianCalendar.setMonth(XMLGregorianCalendar.java:1039)
at javax.xml.datatype.XMLGregorianCalendar.add(XMLGregorianCalendar.java:1982)
at javax.xml.datatype.Duration.compare(Duration.java:626)
at test.main(test.java:7)
----------------------------------------------------
======================================================================