Skip to content

Commit 226dd97

Browse files
committed
Merge branch '2.13' into 2.14
2 parents 82814a2 + ae14e72 commit 226dd97

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ Vlad Tatavu (vladt@github)
287287
for "content reference"
288288
(2.13.2)
289289

290+
PJ Fanning (pjfanning@github)
291+
* Contributed #744: Limit size of exception message in BigDecimalParser
292+
(2.13.3)
293+
290294
Ilya Golovin (ilgo0413@github)
291295
* Contributed #684: Add "JsonPointer#appendProperty" and "JsonPointer#appendIndex"
292296
(2.14.0)

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ JSON library.
2424
floating-point values or not
2525
(contributed Doug R)
2626

27+
2.13.3 (not yet released)
28+
29+
#744: Limit size of exception message in BigDecimalParser
30+
(contributed by @pjfanning))
31+
2732
2.13.2 (06-Mar-2022)
2833

2934
#732: Update Maven wrapper

src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
public final class BigDecimalParser
2323
{
24+
private final static int MAX_CHARS_TO_REPORT = 1000;
2425
private final char[] chars;
2526

2627
BigDecimalParser(char[] chars) {
@@ -51,7 +52,14 @@ public static BigDecimal parse(char[] chars) {
5152
if (desc == null) {
5253
desc = "Not a valid number representation";
5354
}
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
5563
+ "\" can not be represented as `java.math.BigDecimal`, reason: " + desc);
5664
}
5765
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

0 commit comments

Comments
 (0)