Skip to content

Commit fc73bee

Browse files
committed
Fix #563 (async parser, location for array values)
1 parent ce70782 commit fc73bee

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

release-notes/CREDITS-2.x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Doug Roper (htmldoug@github)
155155
* Suggested #463: Ensure that `skipChildren()` of non-blocking `JsonParser` will throw
156156
exception if not enough input
157157
(2.9.6)
158-
* Contributed test for #563: Async parser does not keep track of Array context properly
158+
* Reported, Contributed test for #563: Async parser does not keep track of Array context properly
159159
(2.10.0)
160160
161161
Alexander Eyers-Taylor (aeyerstaylor@github)

release-notes/VERSION-2.x

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ JSON library.
1616

1717
2.10.0.pr3 (16-Sep-2019)
1818

19-
#479: Improve thread-safety of buffer recycling to enable recycling again
20-
for async parsing
19+
#479: Improve thread-safety of buffer recycling
2120
#561: Misleading exception for unquoted String parsing
21+
#563: Async parser does not keep track of Array context properly
22+
(reported by Doug R)
2223

2324
2.10.0.pr2 (31-Aug-2019)
2425

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ private final JsonToken _startValue(int ch) throws IOException
602602
}
603603
}
604604
_updateTokenLocation();
605+
// 17-Sep-2019, tatu: [core#563] Need to call this to update index within array
606+
_parsingContext.expectComma();
607+
605608
if (ch == INT_QUOTE) {
606609
return _startString();
607610
}

src/test/java/com/fasterxml/jackson/failing/AsyncPointerFromContext563Test.java renamed to src/test/java/com/fasterxml/jackson/core/json/async/AsyncPointerFromContext563Test.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.core.json.async;
22

33
import com.fasterxml.jackson.core.*;
44
import com.fasterxml.jackson.core.async.AsyncTestBase;
5-
import com.fasterxml.jackson.core.json.async.NonBlockingJsonParser;
5+
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;
66

77
public class AsyncPointerFromContext563Test extends AsyncTestBase
88
{
@@ -11,11 +11,23 @@ public class AsyncPointerFromContext563Test extends AsyncTestBase
1111
// [core#563]
1212
public void testPointerWithAsyncParser() throws Exception
1313
{
14-
JsonParser p = JSON_F.createNonBlockingByteArrayParser();
1514
final String SIMPLE = aposToQuotes("{'a':123,'array':[1,2,[3],5,{'obInArray':4}],"
1615
+"'ob':{'first':[false,true],'second':{'sub':37}},'b':true}");
1716
byte[] SIMPLE_BYTES = SIMPLE.getBytes("UTF-8");
18-
((NonBlockingJsonParser) p).feedInput(SIMPLE_BYTES, 0, SIMPLE_BYTES.length);
17+
18+
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 1000);
19+
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 7);
20+
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 3);
21+
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 2);
22+
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 1);
23+
24+
_testPointerWithAsyncParser(SIMPLE_BYTES, 20, 5);
25+
_testPointerWithAsyncParser(SIMPLE_BYTES, 14, 1);
26+
}
27+
28+
public void _testPointerWithAsyncParser(byte[] doc, int offset, int readSize) throws Exception
29+
{
30+
AsyncReaderWrapper p = asyncForBytes(JSON_F, readSize, doc, offset);
1931

2032
// by default should just get "empty"
2133
assertSame(JsonPointer.empty(), p.getParsingContext().pathAsPointer());
@@ -24,6 +36,8 @@ public void testPointerWithAsyncParser() throws Exception
2436
assertToken(JsonToken.START_OBJECT, p.nextToken());
2537
assertSame(JsonPointer.empty(), p.getParsingContext().pathAsPointer());
2638

39+
assertEquals("", p.getParsingContext().pathAsPointer().toString());
40+
2741
assertToken(JsonToken.FIELD_NAME, p.nextToken()); // a
2842
assertEquals("/a", p.getParsingContext().pathAsPointer().toString());
2943

@@ -92,8 +106,8 @@ public void testPointerWithAsyncParser() throws Exception
92106
assertToken(JsonToken.END_OBJECT, p.nextToken());
93107
assertSame(JsonPointer.empty(), p.getParsingContext().pathAsPointer());
94108

109+
// note: wrapper maps to `null`, plain async-parser would give NOT_AVAILABLE
95110
assertNull(p.nextToken());
96111
p.close();
97-
98112
}
99113
}

src/test/java/com/fasterxml/jackson/core/testsupport/AsyncReaderWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.fasterxml.jackson.core.JsonParser;
99
import com.fasterxml.jackson.core.JsonParser.NumberType;
10+
import com.fasterxml.jackson.core.JsonStreamContext;
1011
import com.fasterxml.jackson.core.JsonToken;
1112

1213
public abstract class AsyncReaderWrapper
@@ -53,6 +54,10 @@ public String currentName() throws IOException {
5354

5455
public abstract JsonToken nextToken() throws IOException;
5556

57+
public JsonStreamContext getParsingContext() {
58+
return _streamReader.getParsingContext();
59+
}
60+
5661
public int getIntValue() throws IOException { return _streamReader.getIntValue(); }
5762
public long getLongValue() throws IOException { return _streamReader.getLongValue(); }
5863
public float getFloatValue() throws IOException { return _streamReader.getFloatValue(); }

0 commit comments

Comments
 (0)