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) {
143
143
else if (value instanceof BigDecimal ) {
144
144
writeOctet ('D' );
145
145
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 ());
146
152
writeOctet (decimal .scale ());
147
153
BigInteger unscaled = decimal .unscaledValue ();
148
154
// We use 31 instead of 32 because bitLength ignores the sign bit,
Original file line number Diff line number Diff line change 6
6
import java .io .IOException ;
7
7
import java .io .OutputStream ;
8
8
import java .math .BigDecimal ;
9
+ import java .math .BigInteger ;
9
10
import java .util .ArrayDeque ;
10
11
import java .util .Queue ;
11
12
12
13
public class ValueWriterTest {
13
- @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeBigDecimalShouldFail () throws IOException {
14
+ @ Test (expected = IllegalArgumentException .class ) public void writingOverlyLargeBigDecimalShouldFail ()
15
+ throws IOException {
14
16
Queue <Byte > queue = new ArrayDeque <>();
15
17
16
18
OutputStream outputStream = new OutputStream () {
@@ -27,4 +29,22 @@ public void write(int b) {
27
29
valueWriter .writeFieldValue (new BigDecimal (Integer .MAX_VALUE ).add (new BigDecimal (1 )));
28
30
29
31
}
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
+ }
30
50
}
You can’t perform that action at this time.
0 commit comments