File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
main/java/com/rabbitmq/client/impl
test/java/com/rabbitmq/client/impl Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,12 @@ else if(value instanceof Integer) {
143143 else if (value instanceof BigDecimal ) {
144144 writeOctet ('D' );
145145 BigDecimal decimal = (BigDecimal )value ;
146+ // The scale must be an unsigned octet, therefore its values must
147+ // be between 0 and 255
148+ if (decimal .scale () > 255 || decimal .scale () < 0 )
149+ throw new IllegalArgumentException
150+ ("BigDecimal has too large of a scale to be encoded. " +
151+ "The scale was: " + decimal .scale ());
146152 writeOctet (decimal .scale ());
147153 BigInteger unscaled = decimal .unscaledValue ();
148154 // We use 31 instead of 32 because bitLength ignores the sign bit,
Original file line number Diff line number Diff line change 66import java .io .IOException ;
77import java .io .OutputStream ;
88import java .math .BigDecimal ;
9+ import java .math .BigInteger ;
910import java .util .ArrayDeque ;
1011import java .util .Queue ;
1112
1213public class ValueWriterTest {
13- @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeBigDecimalShouldFail () throws IOException {
14+ @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeBigDecimalShouldFail ()
15+ throws IOException {
1416 Queue <Byte > queue = new ArrayDeque <>();
1517
1618 OutputStream outputStream = new OutputStream () {
@@ -27,4 +29,22 @@ public void write(int b) {
2729 valueWriter .writeFieldValue (new BigDecimal (Integer .MAX_VALUE ).add (new BigDecimal (1 )));
2830
2931 }
32+
33+ @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeScaleInBigDecimalShouldFail ()
34+ throws IOException {
35+ Queue <Byte > queue = new ArrayDeque <>();
36+
37+ OutputStream outputStream = new OutputStream () {
38+ @ Override
39+ public void write (int b ) {
40+ queue .add ((byte ) b );
41+ }
42+ };
43+
44+ DataOutputStream dataOutputStream = new DataOutputStream (outputStream );
45+
46+ ValueWriter valueWriter = new ValueWriter (dataOutputStream );
47+
48+ valueWriter .writeFieldValue (new BigDecimal (BigInteger .ONE , 500 ));
49+ }
3050}
You can’t perform that action at this time.
0 commit comments