Skip to content

Commit 32dcb70

Browse files
committed
Fix #476
1 parent f91e8b4 commit 32dcb70

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ JSON library.
1616

1717
2.9.7 (not yet released)
1818

19+
#476: Problem with `BufferRecycler` via async parser (or when sharing parser
20+
across threads)
1921
#477: Exception while decoding Base64 value with escaped `=` character
2022

2123
2.9.6 (12-Jun-2018)

src/main/java/com/fasterxml/jackson/core/JsonFactory.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public JsonParser createNonBlockingByteArrayParser() throws IOException
960960
// 17-May-2017, tatu: Need to take care not to accidentally create JSON parser
961961
// for non-JSON input:
962962
_requireJSONFactory("Non-blocking source not (yet?) support for this format (%s)");
963-
IOContext ctxt = _createContext(null, false);
963+
IOContext ctxt = _createNonBlockingContext(null);
964964
ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChild(_factoryFeatures);
965965
return new NonBlockingJsonParser(ctxt, _parserFeatures, can);
966966
}
@@ -1548,6 +1548,19 @@ protected IOContext _createContext(Object srcRef, boolean resourceManaged) {
15481548
return new IOContext(_getBufferRecycler(), srcRef, resourceManaged);
15491549
}
15501550

1551+
/**
1552+
* Overridable factory method that actually instantiates desired
1553+
* context object for async (non-blocking) parsing
1554+
*
1555+
* @since 2.9.7
1556+
*/
1557+
protected IOContext _createNonBlockingContext(Object srcRef) {
1558+
// [jackson-core#476]: disable buffer recycling for 2.9 to avoid concurrency issues;
1559+
// easiest done by just constructing private "recycler":
1560+
BufferRecycler recycler = new BufferRecycler();
1561+
return new IOContext(recycler, srcRef, false);
1562+
}
1563+
15511564
/**
15521565
* @since 2.8
15531566
*/

src/test/java/com/fasterxml/jackson/core/json/async/AsyncConcurrencyTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ private void _assert(JsonToken exp) throws IOException {
9696
}
9797
}
9898

99+
// [jackson-core#476]
99100
public void testConcurrentAsync() throws Exception
100101
{
101-
for (int i = 0; i < 50; ++i) {
102-
_testConcurrentAsyncOnce(i, 50);
102+
final int MAX_ROUNDS = 30;
103+
for (int i = 0; i < MAX_ROUNDS; ++i) {
104+
_testConcurrentAsyncOnce(i, MAX_ROUNDS);
103105
}
104106
}
105107

0 commit comments

Comments
 (0)