Closed
Description
writeFieldValue
has the following:
else if(value instanceof BigDecimal) {
writeOctet('D');
BigDecimal decimal = (BigDecimal)value;
writeOctet(decimal.scale());
BigInteger unscaled = decimal.unscaledValue();
if(unscaled.bitLength() > 32) /*Integer.SIZE in Java 1.5*/
throw new IllegalArgumentException
("BigDecimal too large to be encoded");
writeLong(decimal.unscaledValue().intValue());
}
but 32
is actually too permissive. It should be 31
because bitLength
ignores the sign bit, meaning that writing new BigDecimal(Integer.Max_Value).add(new BigDecimal(1))
"works" (that is no exception is thrown) and yields a different number back when you read it back using ValueReader
.