Name: erR10175 Date: 12/26/2003
The following method of the class javax.xml.datatype.XMLGregorianCalendar
public static XMLGregorianCalendar fromGregorianCalendar(GregorianCalendar cal)
converts GregorianCalendar to XMLGregorianCalendar incorrectly. The following
fields are not processed as expected: ERA (if it is BC), HOUR_OF_DAY (treated as HOUR).
This bug affects new test in JCK 1.5 (not integrated yet)
api/javax_xml/datatype/XMLGregorianCalendar/index.html#ConvertFrom[FromGregorianCalendar001]
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. Please set the property 'user.timezone' to 'UTC'
(this lets the code be simpler):
------------------------------------------ test.java
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.GregorianCalendar;
class test {
static final String FIELD_UNDEFINED = "FIELD_UNDEFINED";
static String ifdef(int value) {
return value == XMLGregorianCalendar.FIELD_UNDEFINED
? FIELD_UNDEFINED
: (""+value);
}
static String calendar2Str(XMLGregorianCalendar calendar) {
return "(" + calendar.getEonAndYear() + ", "
+ ifdef(calendar.getMonth()) + ", "
+ ifdef(calendar.getDay()) + ", "
+ ifdef(calendar.getHour()) + ", "
+ ifdef(calendar.getMinute()) + ", "
+ ifdef(calendar.getSecond()) + ", "
+ (calendar.getMillisecond() == XMLGregorianCalendar.FIELD_UNDEFINED
? FIELD_UNDEFINED
: (""+calendar.getMillisecond()/1000.0F)) + ", "
+ ifdef(calendar.getTimezone())
+ ")";
}
public static void main(String [] args) {
GregorianCalendar calendar1
= new GregorianCalendar(1234, 0, 02, 14, 15, 57);
calendar1.set(GregorianCalendar.ERA, GregorianCalendar.BC);
calendar1.set(GregorianCalendar.MILLISECOND, 456);
XMLGregorianCalendar returned
= XMLGregorianCalendar.fromGregorianCalendar(calendar1);
XMLGregorianCalendar expected
= XMLGregorianCalendar.parse("-1234-01-02T14:15:57.456Z");
if (!returned.equals(expected)) {
System.out.println("returned " + calendar2Str(returned)
+ ", expected " + calendar2Str(expected));
} else {
System.out.println("OK");
}
}
}
----------------------------------------------------
------------------------------------------------ log
$javac test.java && java -Duser.timezone=UTC -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)
returned (1234, 1, 2, 2, 15, 57, 0.456, 0), expected (-1234, 1, 2, 14, 15, 57, 0.456, 0)
----------------------------------------------------
======================================================================