[JAXP-57] XMLGregorianCalendar's method "toString()" sometimes brakes ISO date format in fractional seconds Created: 19/Feb/09  Updated: 19/Feb/09

Status: Open
Project: jaxp
Component/s: www
Affects Version/s: current
Fix Version/s: milestone 1

Type: Bug Priority: Major
Reporter: genoko Assignee: jaxp-issues
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Issuezilla Id: 57

 Description   

XMLGregorianCalendar is used by JAX-WS to generate values for xs:dateTime in XML
documents. Sometimes, the output is broken and contains illegal characters; here
"E-9" instead of fractional seconds.

The code of my converter routine is:
public static final XMLGregorianCalendar xmlValueOf(
java.sql.Timestamp sqlValue )
{
logger.log(
Level.FINE, "java.sql.Timestamp sqlValue=

{0}", sqlValue.toString() );
if (sqlValue == null) { return null; }
GregorianCalendar calendar = new GregorianCalendar(UTC_TZ, Locale.ROOT);
logger.log(Level.FINER, "GregorianCalendar calendar={0}

", calendar);
calendar.setTime(new Date(sqlValue.getTime()));
logger.log(Level.FINER, "GregorianCalendar calendar=

{0}", calendar);
XMLGregorianCalendar result
= datatypeFactory.newXMLGregorianCalendar(calendar);
logger.log(Level.FINER, "XMLGregorianCalendar result={0}

", result);
int sqlNanoseconds = sqlValue.getNanos();
logger.log(
Level.FINER, "java.sql.Timestamp int nanoseconds=

{0}", sqlNanoseconds );
BigDecimal nanoseconds = new BigDecimal(sqlNanoseconds);
logger.log(Level.FINER, "BigDecimal nanoseconds={0}

", nanoseconds);
BigDecimal nanosecondsFractional
= nanoseconds.divide(BILLION, 9, RoundingMode.HALF_UP);
logger.log(
Level.FINER,
"BigDecimal nanosecondsFractional=

{0}", nanosecondsFractional );
result.setFractionalSecond(nanosecondsFractional);
logger.log(Level.FINE, "XMLGregorianCalendar result={0}

", result);
return result;
}

And here is an example for broken output:

FEIN: java.sql.Timestamp sqlValue=2009-02-01 00:00:00.0
FEINER: GregorianCalendar
calendar=java.util.GregorianCalendar[time=1235046117468,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=1,WEEK_OF_YEAR=8,WEEK_OF_MONTH=3,DAY_OF_MONTH=19,DAY_OF_YEAR=50,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=0,HOUR_OF_DAY=12,MINUTE=21,SECOND=57,MILLISECOND=468,ZONE_OFFSET=0,DST_OFFSET=0]
FEINER: GregorianCalendar
calendar=java.util.GregorianCalendar[time=1233446400000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=1,WEEK_OF_YEAR=6,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=32,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]
FEINER: XMLGregorianCalendar result=2009-02-01T00:00:00.000Z
FEINER: java.sql.Timestamp int nanoseconds=0
FEINER: BigDecimal nanoseconds=0
FEINER: BigDecimal nanosecondsFractional=0
FEIN: XMLGregorianCalendar result=2009-02-01T00:00:00E-9Z

The XML SOAP request sent included the following broken xs:dateTime value:

<startUTC>2009-02-01T00:00:00E-9Z</startUTC>

It seems that "setFractionalSecond()" triggers the error here.

We need microseconds in our application, therefore "java.util.Date" or
"java.util.GregorianCalendar" is not useable.


Generated at Tue Mar 31 18:37:40 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.