Skip to content

Commit

Permalink
Fix #476
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 18, 2018
1 parent f91e8b4 commit 32dcb70
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ JSON library.

2.9.7 (not yet released)

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

2.9.6 (12-Jun-2018)
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/fasterxml/jackson/core/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ public JsonParser createNonBlockingByteArrayParser() throws IOException
// 17-May-2017, tatu: Need to take care not to accidentally create JSON parser
// for non-JSON input:
_requireJSONFactory("Non-blocking source not (yet?) support for this format (%s)");
IOContext ctxt = _createContext(null, false);
IOContext ctxt = _createNonBlockingContext(null);
ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChild(_factoryFeatures);
return new NonBlockingJsonParser(ctxt, _parserFeatures, can);
}
Expand Down Expand Up @@ -1548,6 +1548,19 @@ protected IOContext _createContext(Object srcRef, boolean resourceManaged) {
return new IOContext(_getBufferRecycler(), srcRef, resourceManaged);
}

/**
* Overridable factory method that actually instantiates desired
* context object for async (non-blocking) parsing
*
* @since 2.9.7
*/
protected IOContext _createNonBlockingContext(Object srcRef) {
// [jackson-core#476]: disable buffer recycling for 2.9 to avoid concurrency issues;
// easiest done by just constructing private "recycler":
BufferRecycler recycler = new BufferRecycler();
return new IOContext(recycler, srcRef, false);
}

/**
* @since 2.8
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ private void _assert(JsonToken exp) throws IOException {
}
}

// [jackson-core#476]
public void testConcurrentAsync() throws Exception
{
for (int i = 0; i < 50; ++i) {
_testConcurrentAsyncOnce(i, 50);
final int MAX_ROUNDS = 30;
for (int i = 0; i < MAX_ROUNDS; ++i) {
_testConcurrentAsyncOnce(i, MAX_ROUNDS);
}
}

Expand Down

0 comments on commit 32dcb70

Please sign in to comment.