Skip to content

Commit 24ced5f

Browse files
committed
Merge branch '2.10' into 2.11
2 parents e37053e + 3e0e853 commit 24ced5f

File tree

8 files changed

+83
-43
lines changed

8 files changed

+83
-43
lines changed

release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ Volkan Yazıcı (vy@github)
224224
`writeString(Reader, int)`
225225
(2.10.4 [partial], 2.11.0 [full fix])
226226

227+
Justin Liu (jusliu@github)
228+
* Reported #616: Parsing JSON with `ALLOW_MISSING_VALUE` enabled results in endless stream
229+
of `VALUE_NULL` tokens
230+
(2.10.5)
231+
227232
Michel Feinstein (feinstein@github)
228233
* Requested #504: Add a String Array write method in the Streaming API
229234
(2.11.0)

release-notes/VERSION-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ JSON library.
2828
#611: Optionally allow leading decimal in float tokens
2929
(contributed by James A)
3030

31+
2.10.5 (not yet released)
32+
33+
#616: Parsing JSON with `ALLOW_MISSING_VALUE` enabled results in endless stream
34+
of `VALUE_NULL` tokens
35+
(reported by Justin L)
36+
3137
2.10.4 (03-May-2020)
3238

3339
#605: Handle case when system property access is restricted

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,17 +1147,20 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
11471147
return (_currToken = _parsePosNumber(i));
11481148
/*
11491149
* This check proceeds only if the Feature.ALLOW_MISSING_VALUES is enabled
1150-
* The Check is for missing values. Incase of missing values in an array, the next token will be either ',' or ']'.
1150+
* The Check is for missing values. In case of missing values in an array, the next token will be either ',' or ']'.
11511151
* This case, decrements the already incremented _inputPtr in the buffer in case of comma(,)
11521152
* so that the existing flow goes back to checking the next token which will be comma again and
11531153
* it continues the parsing.
11541154
* Also the case returns NULL as current token in case of ',' or ']'.
11551155
*/
1156+
// case ']': // 11-May-2020, tatu: related to [core#616], this should never be reached
11561157
case ',':
1157-
case ']':
1158-
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
1159-
--_inputPtr;
1160-
return (_currToken = JsonToken.VALUE_NULL);
1158+
// 11-May-2020, tatu: [core#616] No commas in root level
1159+
if (!_parsingContext.inRoot()) {
1160+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
1161+
--_inputPtr;
1162+
return (_currToken = JsonToken.VALUE_NULL);
1163+
}
11611164
}
11621165
}
11631166
return (_currToken = _handleOddValue(i));
@@ -1906,9 +1909,12 @@ protected JsonToken _handleOddValue(int i) throws IOException
19061909
}
19071910
// fall through
19081911
case ',':
1909-
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
1910-
--_inputPtr;
1911-
return JsonToken.VALUE_NULL;
1912+
// 11-May-2020, tatu: [core#616] No commas in root level
1913+
if (!_parsingContext.inRoot()) {
1914+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
1915+
--_inputPtr;
1916+
return JsonToken.VALUE_NULL;
1917+
}
19121918
}
19131919
break;
19141920
case 'N':

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,10 +2050,13 @@ protected JsonToken _handleUnexpectedValue(int c)
20502050
/* !!! TODO: 08-May-2016, tatu: To support `Feature.ALLOW_MISSING_VALUES` would
20512051
* need handling here...
20522052
*/
2053-
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
2053+
// 11-May-2020, tatu: [core#616] No commas in root level
2054+
if (!_parsingContext.inRoot()) {
2055+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
20542056
// _inputPtr--;
2055-
_nextByte = c;
2056-
return JsonToken.VALUE_NULL;
2057+
_nextByte = c;
2058+
return JsonToken.VALUE_NULL;
2059+
}
20572060
}
20582061
// fall through
20592062
case '}':

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,9 +2639,12 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
26392639
// 28-Mar-2016: [core#116]: If Feature.ALLOW_MISSING_VALUES is enabled
26402640
// we may allow "missing values", that is, encountering a trailing
26412641
// comma or closing marker where value would be expected
2642-
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
2643-
--_inputPtr;
2644-
return JsonToken.VALUE_NULL;
2642+
// 11-May-2020, tatu: [core#616] No commas in root level
2643+
if (!_parsingContext.inRoot()) {
2644+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
2645+
--_inputPtr;
2646+
return JsonToken.VALUE_NULL;
2647+
}
26452648
}
26462649
// fall through
26472650
case '}':

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,12 @@ protected JsonToken _startUnexpectedValue(boolean leadingComma, int ch) throws I
918918
// 28-Mar-2016: [core#116]: If Feature.ALLOW_MISSING_VALUES is enabled
919919
// we may allow "missing values", that is, encountering a trailing
920920
// comma or closing marker where value would be expected
921-
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
922-
--_inputPtr;
923-
return _valueComplete(JsonToken.VALUE_NULL);
921+
// 11-May-2020, tatu: [core#616] No commas in root level
922+
if (!_parsingContext.inRoot()) {
923+
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
924+
--_inputPtr;
925+
return _valueComplete(JsonToken.VALUE_NULL);
926+
}
924927
}
925928
// fall through
926929
case INT_RCURLY:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.core.read;
2+
3+
import com.fasterxml.jackson.core.*;
4+
import com.fasterxml.jackson.core.json.JsonReadFeature;
5+
6+
public class TrailingCommas616Test extends BaseTest
7+
{
8+
final JsonFactory f = JsonFactory.builder()
9+
.enable(JsonReadFeature.ALLOW_MISSING_VALUES)
10+
.build();
11+
12+
// [core#616]
13+
public void testRootLevelComma616() throws Exception
14+
{
15+
_testRootLevel616(f, MODE_READER);
16+
}
17+
18+
public void testRootLevelComma616Bytes() throws Exception
19+
{
20+
_testRootLevel616(f, MODE_INPUT_STREAM);
21+
_testRootLevel616(f, MODE_INPUT_STREAM_THROTTLED);
22+
}
23+
24+
public void testRootLevelComma616DataInput() throws Exception
25+
{
26+
_testRootLevel616(f, MODE_DATA_INPUT);
27+
}
28+
29+
private void _testRootLevel616(JsonFactory f, int mode) throws Exception
30+
{
31+
JsonParser p = createParser(f, mode, ",");
32+
try {
33+
p.nextToken();
34+
fail("Should not pass");
35+
} catch (JsonParseException e) {
36+
verifyException(e, "Unexpected character (','");
37+
}
38+
p.close();
39+
}
40+
}

src/test/java/com/fasterxml/jackson/failing/TrailingCommas616Test.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)