File tree 4 files changed +36
-1
lines changed
main/java/com/fasterxml/jackson/core/io
test/java/com/fasterxml/jackson/core/io
4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,10 @@ Vlad Tatavu (vladt@github)
287
287
for "content reference"
288
288
(2.13 .2 )
289
289
290
+ PJ Fanning (pjfanning @github )
291
+ * Contributed #744 : Limit size of exception message in BigDecimalParser
292
+ (2.13 .3 )
293
+
290
294
Ilya Golovin (ilgo0413 @github )
291
295
* Contributed #684 : Add "JsonPointer#appendProperty" and "JsonPointer#appendIndex"
292
296
(2.14 .0 )
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ JSON library.
24
24
floating - point values or not
25
25
(contributed Doug R )
26
26
27
+ 2.13 .3 (not yet released )
28
+
29
+ #744 : Limit size of exception message in BigDecimalParser
30
+ (contributed by @pjfanning ))
31
+
27
32
2.13 .2 (06 - Mar - 2022 )
28
33
29
34
#732 : Update Maven wrapper
Original file line number Diff line number Diff line change 21
21
*/
22
22
public final class BigDecimalParser
23
23
{
24
+ private final static int MAX_CHARS_TO_REPORT = 1000 ;
24
25
private final char [] chars ;
25
26
26
27
BigDecimalParser (char [] chars ) {
@@ -51,7 +52,14 @@ public static BigDecimal parse(char[] chars) {
51
52
if (desc == null ) {
52
53
desc = "Not a valid number representation" ;
53
54
}
54
- throw new NumberFormatException ("Value \" " + new String (chars )
55
+ String stringToReport ;
56
+ if (chars .length <= MAX_CHARS_TO_REPORT ) {
57
+ stringToReport = new String (chars );
58
+ } else {
59
+ stringToReport = new String (Arrays .copyOfRange (chars , 0 , MAX_CHARS_TO_REPORT ))
60
+ + "(truncated, full length is " + chars .length + " chars)" ;
61
+ }
62
+ throw new NumberFormatException ("Value \" " + stringToReport
55
63
+ "\" can not be represented as `java.math.BigDecimal`, reason: " + desc );
56
64
}
57
65
}
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .core .io ;
2
+
3
+ public class BigDecimalParserTest extends com .fasterxml .jackson .core .BaseTest {
4
+ public void testLongStringParse () {
5
+ final int len = 1500 ;
6
+ final StringBuilder sb = new StringBuilder (len );
7
+ for (int i = 0 ; i < len ; i ++) {
8
+ sb .append ("A" );
9
+ }
10
+ try {
11
+ BigDecimalParser .parse (sb .toString ());
12
+ fail ("expected NumberFormatException" );
13
+ } catch (NumberFormatException nfe ) {
14
+ assertTrue ("exception message starts as expected?" , nfe .getMessage ().startsWith ("Value \" AAAAA" ));
15
+ assertTrue ("exception message value contains truncated" , nfe .getMessage ().contains ("truncated" ));
16
+ }
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments