Skip to content

Commit 3db9cb4

Browse files
ferenc-csakyFerenc Csaky
andauthored
fixed bigdecimal parser (#678)
Co-authored-by: Ferenc Csaky <[email protected]>
1 parent 5de0c67 commit 3db9cb4

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,24 @@
88
public final class BigDecimalParser {
99

1010
private final char[] chars;
11-
private final int off;
1211
private final int len;
1312

14-
BigDecimalParser(char[] chars, int off, int len) {
13+
BigDecimalParser(char[] chars) {
1514
this.chars = chars;
16-
this.off = off;
17-
this.len = len;
15+
len = chars.length;
1816
}
1917

2018
BigDecimal parse() throws NumberFormatException {
2119
try {
22-
if (len < 500) {
23-
return new BigDecimal(chars, off, len);
20+
if (chars.length < 500) {
21+
return new BigDecimal(chars);
2422
}
2523

26-
int splitLen = len / 10;
24+
int splitLen = chars.length / 10;
2725
return parseBigDecimal(splitLen);
2826

2927
} catch (NumberFormatException e) {
30-
String val = new String(chars, off, len);
31-
32-
throw new NumberFormatException("Value \"" + val + "\" can not be represented as BigDecimal."
28+
throw new NumberFormatException("Value \"" + new String(chars) + "\" can not be represented as BigDecimal."
3329
+ " Reason: " + e.getMessage());
3430
}
3531
}
@@ -43,7 +39,7 @@ private BigDecimal parseBigDecimal(int splitLen) {
4339
int dotIdx = -1;
4440
int scale = 0;
4541

46-
for (int i = off; i < len; i++) {
42+
for (int i = 0; i < len; i++) {
4743
char c = chars[i];
4844
switch (c) {
4945
case '+':

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,15 @@ public static BigDecimal parseBigDecimal(String s) throws NumberFormatException
316316
return parseBigDecimal(ch);
317317
}
318318

319-
public static BigDecimal parseBigDecimal(char[] ch) throws NumberFormatException {
320-
return parseBigDecimal(ch, 0, ch.length);
319+
public static BigDecimal parseBigDecimal(char[] ch, int off, int len) throws NumberFormatException {
320+
char[] copy = new char[len];
321+
System.arraycopy(ch, off, copy, 0, len);
322+
323+
return parseBigDecimal(copy);
321324
}
322325

323-
public static BigDecimal parseBigDecimal(char[] ch, int off, int len) throws NumberFormatException {
324-
BigDecimalParser parser = new BigDecimalParser(ch, off, len);
326+
public static BigDecimal parseBigDecimal(char[] ch) throws NumberFormatException {
327+
BigDecimalParser parser = new BigDecimalParser(ch);
325328

326329
return parser.parse();
327330
}

0 commit comments

Comments
 (0)