Skip to content

Commit 345cad5

Browse files
committed
Fix #317
1 parent 930edea commit 345cad5

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

release-notes/CREDITS

+5
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ Mike Naseef (mtnaseef@github)
8888
* Reported #307: JsonGenerationException: Split surrogate on writeRaw() input thrown for
8989
input of a certain size
9090
(2.7.7)
91+
92+
Allar Haav (haav@github)
93+
* Reportef #317: ArrayIndexOutOfBoundsException: 200 on floating point number with exactly
94+
200-length decimal part
95+
(2.7.8)

release-notes/VERSION

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.7.8 (not yet released)
18+
19+
#317: ArrayIndexOutOfBoundsException: 200 on floating point number with exactly
20+
200-length decimal part
21+
(reported by Allar H)
22+
1723
2.7.7 (27-Aug-2016)
1824

1925
#307: JsonGenerationException: Split surrogate on writeRaw() input thrown for

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

+4
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,10 @@ private final JsonToken _parseNumber2(boolean neg, int startPtr) throws IOExcept
14151415
int fractLen = 0;
14161416
// And then see if we get other parts
14171417
if (c == '.') { // yes, fraction
1418+
if (outPtr >= outBuf.length) {
1419+
outBuf = _textBuffer.finishCurrentSegment();
1420+
outPtr = 0;
1421+
}
14181422
outBuf[outPtr++] = c;
14191423

14201424
fract_loop:

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,10 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c,
15411541

15421542
// And then see if we get other parts
15431543
if (c == INT_PERIOD) { // yes, fraction
1544+
if (outPtr >= outBuf.length) {
1545+
outBuf = _textBuffer.finishCurrentSegment();
1546+
outPtr = 0;
1547+
}
15441548
outBuf[outPtr++] = (char) c;
15451549

15461550
fract_loop:
@@ -1615,7 +1619,7 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c,
16151619
// Ok; unless we hit end-of-input, need to push last char read back
16161620
if (!eof) {
16171621
--_inputPtr;
1618-
// As per #105, need separating space between root values; check here
1622+
// As per [core#105], need separating space between root values; check here
16191623
if (_parsingContext.inRoot()) {
16201624
_verifyRootSpace(c);
16211625
}

src/test/java/com/fasterxml/jackson/core/json/TestNumericValues.java

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.fasterxml.jackson.core.json;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.io.IOException;
5+
import java.io.StringReader;
36
import java.math.BigDecimal;
47
import java.math.BigInteger;
58

@@ -550,6 +553,35 @@ public void testInvalidIntAccess() throws Exception
550553
jp.close();
551554
}
552555

556+
// [core#317]
557+
public void testLongerFloatingPoint() throws Exception
558+
{
559+
StringBuilder input = new StringBuilder();
560+
for (int i = 1; i < 201; i++) {
561+
input.append(1);
562+
}
563+
input.append(".0");
564+
final String DOC = input.toString();
565+
566+
// test out with both Reader and ByteArrayInputStream
567+
JsonParser p;
568+
569+
p = FACTORY.createParser(new StringReader(DOC));
570+
_testLongerFloat(p, DOC);
571+
p.close();
572+
573+
p = FACTORY.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")));
574+
_testLongerFloat(p, DOC);
575+
p.close();
576+
}
577+
578+
private void _testLongerFloat(JsonParser p, String text) throws IOException
579+
{
580+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
581+
assertEquals(text, p.getText());
582+
assertNull(p.nextToken());
583+
}
584+
553585
/*
554586
/**********************************************************
555587
/* Helper methods

0 commit comments

Comments
 (0)