[PR] Fix printDecimal regression for decimal values wider than a long [poi-xmlbeans]

czpilar (via GitHub) <[email protected]>
Newsgroups gmane.comp.jakarta.poi.devel
Message-ID <[email protected]>
czpilar opened a new pull request, #96:
URL: https://github.com/apache/poi-xmlbeans/pull/96

   Regression introduced in 5.4.0: printing any xsd:decimal that has a non-zero scale and does not fit into a long throws IllegalArgumentException("Value can't be converted to long"). 5.3.0 prints the same value correctly.
   
   XsTypeConverter.printDecimal calls MathUtil.toLong(value) as the left operand of an && whose right operand is the "scale < 0" guard. Java evaluates && left to right, so toLong() runs for every value with a non-zero scale. Its result only matters when the scale is negative - in which case the value is integral and always fits into a long - but by then the exception has already been thrown.
   
   5.3.0 used BigDecimal.longValue() on that line, which truncates silently instead of throwing, so the condition was simply false and printing proceeded. MathUtil was added in 5.4.0 and toLong() replaced longValue() here.
   
   Swapping the operands restores the old behaviour without changing the semantics.
   
   Seen in the wild as a WSDL2Java code generation failure: xmlbeans could no longer save a compiled schema type system containing a high-precision decimal.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.