File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
main/java/com/fasterxml/jackson/core/io
test/java/com/fasterxml/jackson/core/io Expand file tree Collapse file tree 2 files changed +27
-1
lines changed 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