Skip to content

Commit

Permalink
Change # of bits ValueWriter checks for BigDecimal
Browse files Browse the repository at this point in the history
Move from 32 to 31 because bitLength ignores the sign bit.

(cherry picked from commit fe58bd6)
  • Loading branch information
changlinli authored and acogoluegnes committed Jun 28, 2019
1 parent a0bfd6e commit 8c0185a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/rabbitmq/client/impl/ValueWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ else if(value instanceof BigDecimal) {
BigDecimal decimal = (BigDecimal)value;
writeOctet(decimal.scale());
BigInteger unscaled = decimal.unscaledValue();
if(unscaled.bitLength() > 32) /*Integer.SIZE in Java 1.5*/
// We use 31 instead of 32 because bitLength ignores the sign bit,
// so e.g. new BigDecimal(Integer.MAX_VALUE) comes out to 31 bits.
if(unscaled.bitLength() > 31) /*Integer.SIZE in Java 1.5*/
throw new IllegalArgumentException
("BigDecimal too large to be encoded");
writeLong(decimal.unscaledValue().intValue());
Expand Down

0 comments on commit 8c0185a

Please sign in to comment.