castor

Usage of BigDecial.toString() in Marshaller inconsistent when switching from Java 1.4 (and below) to Java 5.0 (and above)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.1
  • Fix Version/s: 1.1.2
  • Component/s: XML
  • Labels:
    None
  • Number of attachments :
    0

Description

Apparently, Sun decided to change the semantics of BigDecimal.toString() with the release of Java 5.0, allowing scientific notation to be 'produced' when calculating the String representation of a BigDecimal instance. With Java 5.0, BigDecimal.toString() can return a String in scientific notation. As we use a BigDecimal for the XML schema type <xs:decimal>, this is illegal (as per XML schema specification, this is not allowed).

As a result of this, BigDecimal.toPlainString() should be used for Java 5.0 and above (ideally for BigDecimals representing ,xs>decimal> only). It looks like the code in question (within Marshaller) will have to take into account the JVM release number to make an educated decision.

Issue Links

Activity

Hide
Ralf Joachim added a comment -

Or you use DecimalFormat to format the output which should produce similar results for both Java versions.

Show
Ralf Joachim added a comment - Or you use DecimalFormat to format the output which should produce similar results for both Java versions.
Hide
Werner Guttmann added a comment -

Checked in a change to Marshaller that uses the java.specification.version property to selectively call either BigDecimal.toString() or BigDecimal.toPlainString().

Show
Werner Guttmann added a comment - Checked in a change to Marshaller that uses the java.specification.version property to selectively call either BigDecimal.toString() or BigDecimal.toPlainString().
Hide
Werner Guttmann added a comment -

as patch has been shipped as part of CASTOR-1904.

Show
Werner Guttmann added a comment - as patch has been shipped as part of CASTOR-1904.
Hide
Dmitry Savenko added a comment -

There is a note still. You base your decision which method to be use on java.specification.version system property:
*************************************
1995 private String convertBigDecimalToString(Object object) throws MarshalException {
1996 String stringValue;
1997 float javaVersion = Float.parseFloat(System.getProperty("java.specification.version"));
1998 if (javaVersion > 5.0) {
1999 // as of Java 5.0 and above, BigDecimal.toPlainString() should be used.
2000 // TODO: reconsider if we start using BigDecimal for XSTypes that can hold scientific values
*************************************
for Java 1.5.0_09-b03
Float.parseFloat(System.getProperty("java.specification.version")) is 1.5 !!!

Show
Dmitry Savenko added a comment - There is a note still. You base your decision which method to be use on java.specification.version system property: ************************************* 1995 private String convertBigDecimalToString(Object object) throws MarshalException { 1996 String stringValue; 1997 float javaVersion = Float.parseFloat(System.getProperty("java.specification.version")); 1998 if (javaVersion > 5.0) { 1999 // as of Java 5.0 and above, BigDecimal.toPlainString() should be used. 2000 // TODO: reconsider if we start using BigDecimal for XSTypes that can hold scientific values ************************************* for Java 1.5.0_09-b03 Float.parseFloat(System.getProperty("java.specification.version")) is 1.5 !!!

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
1h
Original Estimate - 1 hour
Remaining:
1h
Remaining Estimate - 1 hour
Logged:
Not Specified
Time Spent - Not Specified