Skip to content

Commit f14d2ed

Browse files
committed
Update release notes wrt #828
1 parent 351de07 commit f14d2ed

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ JSON library.
7373
throws `StackOverflowErrror`
7474
#822: Declare osgi.serviceloader.registrar requirement as optional
7575
(contributed by Chris R)
76+
#828: Make `BigInteger` parsing lazy
77+
(contributed by @pjfanning)
7678

7779
2.13.4 (03-Sep-2022)
7880

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ public abstract class ParserBase extends ParserMinimalBase
203203

204204
protected BigDecimal _numberBigDecimal;
205205

206+
/**
207+
* Textual number representation captured from input in cases lazy-parsing
208+
* is desired.
209+
*<p>
210+
* As of 2.14 this only applies to {@link BigInteger}.
211+
*
212+
* @since 2.14
213+
*/
206214
protected String _numberString;
207215

208216
// And then other information about value itself
@@ -609,7 +617,7 @@ public Number getNumberValue() throws IOException
609617
return _numberLong;
610618
}
611619
if ((_numTypesValid & NR_BIGINT) != 0) {
612-
return getBigInteger();
620+
return _getBigInteger();
613621
}
614622
_throwInternal();
615623
}
@@ -643,7 +651,7 @@ public Number getNumberValueExact() throws IOException
643651
return _numberLong;
644652
}
645653
if ((_numTypesValid & NR_BIGINT) != 0) {
646-
return getBigInteger();
654+
return _getBigInteger();
647655
}
648656
_throwInternal();
649657
}
@@ -733,7 +741,7 @@ public BigInteger getBigIntegerValue() throws IOException
733741
convertNumberToBigInteger();
734742
}
735743
}
736-
return getBigInteger();
744+
return _getBigInteger();
737745
}
738746

739747
@Override
@@ -971,7 +979,7 @@ protected void convertNumberToInt() throws IOException
971979
}
972980
_numberInt = result;
973981
} else if ((_numTypesValid & NR_BIGINT) != 0) {
974-
final BigInteger bigInteger = getBigInteger();
982+
final BigInteger bigInteger = _getBigInteger();
975983
if (BI_MIN_INT.compareTo(bigInteger) > 0
976984
|| BI_MAX_INT.compareTo(bigInteger) < 0) {
977985
reportOverflowInt();
@@ -1000,7 +1008,7 @@ protected void convertNumberToLong() throws IOException
10001008
if ((_numTypesValid & NR_INT) != 0) {
10011009
_numberLong = (long) _numberInt;
10021010
} else if ((_numTypesValid & NR_BIGINT) != 0) {
1003-
final BigInteger bigInteger = getBigInteger();
1011+
final BigInteger bigInteger = _getBigInteger();
10041012
if (BI_MIN_LONG.compareTo(bigInteger) > 0
10051013
|| BI_MAX_LONG.compareTo(bigInteger) < 0) {
10061014
reportOverflowLong();
@@ -1052,7 +1060,7 @@ protected void convertNumberToDouble() throws IOException
10521060
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
10531061
_numberDouble = _numberBigDecimal.doubleValue();
10541062
} else if ((_numTypesValid & NR_BIGINT) != 0) {
1055-
_numberDouble = getBigInteger().doubleValue();
1063+
_numberDouble = _getBigInteger().doubleValue();
10561064
} else if ((_numTypesValid & NR_LONG) != 0) {
10571065
_numberDouble = (double) _numberLong;
10581066
} else if ((_numTypesValid & NR_INT) != 0) {
@@ -1076,7 +1084,7 @@ protected void convertNumberToFloat() throws IOException
10761084
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
10771085
_numberFloat = _numberBigDecimal.floatValue();
10781086
} else if ((_numTypesValid & NR_BIGINT) != 0) {
1079-
_numberFloat = getBigInteger().floatValue();
1087+
_numberFloat = _getBigInteger().floatValue();
10801088
} else if ((_numTypesValid & NR_LONG) != 0) {
10811089
_numberFloat = (float) _numberLong;
10821090
} else if ((_numTypesValid & NR_INT) != 0) {
@@ -1098,12 +1106,11 @@ protected void convertNumberToBigDecimal() throws IOException
10981106
*/
10991107

11001108
if ((_numTypesValid & NR_DOUBLE) != 0) {
1101-
/* Let's actually parse from String representation, to avoid
1102-
* rounding errors that non-decimal floating operations could incur
1103-
*/
1109+
// Let's actually parse from String representation, to avoid
1110+
// rounding errors that non-decimal floating operations could incur
11041111
_numberBigDecimal = NumberInput.parseBigDecimal(getText());
11051112
} else if ((_numTypesValid & NR_BIGINT) != 0) {
1106-
_numberBigDecimal = new BigDecimal(getBigInteger());
1113+
_numberBigDecimal = new BigDecimal(_getBigInteger());
11071114
} else if ((_numTypesValid & NR_LONG) != 0) {
11081115
_numberBigDecimal = BigDecimal.valueOf(_numberLong);
11091116
} else if ((_numTypesValid & NR_INT) != 0) {
@@ -1114,6 +1121,23 @@ protected void convertNumberToBigDecimal() throws IOException
11141121
_numTypesValid |= NR_BIGDECIMAL;
11151122
}
11161123

1124+
/**
1125+
* Internal accessor that needs to be used for accessing number value of type
1126+
* {@link BigInteger} which -- as of 2.14 -- is typically lazily parsed.
1127+
*
1128+
* @since 2.14
1129+
*/
1130+
protected BigInteger _getBigInteger() {
1131+
if (_numberBigInt != null) {
1132+
return _numberBigInt;
1133+
} else if (_numberString == null) {
1134+
throw new IllegalStateException("cannot get BigInteger from current parser state");
1135+
}
1136+
_numberBigInt = NumberInput.parseBigInteger(_numberString);
1137+
_numberString = null;
1138+
return _numberBigInt;
1139+
}
1140+
11171141
/*
11181142
/**********************************************************
11191143
/* Internal/package methods: Error reporting
@@ -1332,7 +1356,7 @@ protected static int[] growArrayBy(int[] arr, int more)
13321356
}
13331357
return Arrays.copyOf(arr, arr.length + more);
13341358
}
1335-
1359+
13361360
/*
13371361
/**********************************************************
13381362
/* Stuff that was abstract and required before 2.8, but that
@@ -1350,15 +1374,4 @@ protected void loadMoreGuaranteed() throws IOException {
13501374

13511375
// Can't declare as deprecated, for now, but shouldn't be needed
13521376
protected void _finishString() throws IOException { }
1353-
1354-
private BigInteger getBigInteger() {
1355-
if (_numberBigInt != null) {
1356-
return _numberBigInt;
1357-
} else if (_numberString == null) {
1358-
throw new IllegalStateException("cannot get BigInteger from current parser state");
1359-
}
1360-
_numberBigInt = NumberInput.parseBigInteger(_numberString);
1361-
_numberString = null;
1362-
return _numberBigInt;
1363-
}
13641377
}

0 commit comments

Comments
 (0)