diff --git a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java index c5b6b59f81..8fbaa77c9e 100644 --- a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java +++ b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java @@ -21,6 +21,7 @@ */ public final class BigDecimalParser { + private final static int MAX_CHARS_TO_REPORT = 1000; private final char[] chars; BigDecimalParser(char[] chars) { @@ -51,7 +52,14 @@ public static BigDecimal parse(char[] chars) { if (desc == null) { desc = "Not a valid number representation"; } - throw new NumberFormatException("Value \"" + new String(chars) + String stringToReport; + if (chars.length <= MAX_CHARS_TO_REPORT) { + stringToReport = new String(chars); + } else { + stringToReport = new String(Arrays.copyOfRange(chars, 0, MAX_CHARS_TO_REPORT)) + + "(truncated, full length is " + chars.length + " chars)"; + } + throw new NumberFormatException("Value \"" + stringToReport + "\" can not be represented as `java.math.BigDecimal`, reason: " + desc); } } diff --git a/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java b/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java new file mode 100644 index 0000000000..436d74cd1d --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.core.io; + +public class BigDecimalParserTest extends com.fasterxml.jackson.core.BaseTest { + public void testLongStringParse() { + final int len = 1500; + final StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) { + sb.append("A"); + } + try { + BigDecimalParser.parse(sb.toString()); + fail("expected NumberFormatException"); + } catch (NumberFormatException nfe) { + assertTrue("exception message starts as expected?", nfe.getMessage().startsWith("Value \"AAAAA")); + assertTrue("exception message value contains truncated", nfe.getMessage().contains("truncated")); + } + } +}