Skip to content

Commit

Permalink
Fix #738
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 27, 2015
1 parent 48617c8 commit ec1820d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@ Antibrumm@github:
Francisco A. Lozano (flozano@github)
* Contributed fix for #703 (see above)
(2.5.2)

Dylan Scott (dylanscott@github)
* Reported #738: #738: @JsonTypeInfo non-deterministically ignored in 2.5.1 (concurrency
issue)
(2.5.2)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project: jackson-databind
(reported by jkochaniak@github)
#733: MappingIterator should move past errors or not return hasNext() == true
(reported by Lorrin N, lorrin@github)
#738: @JsonTypeInfo non-deterministically ignored in 2.5.1 (concurrency issue)
(reported by Dylan S, dylanscott@github)
- Improvement to handling of custom `ValueInstantiator` for delegating mode; no more NPE
if `getDelegateCreator()` returns null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,13 @@ protected JsonSerializer<Object> _findExplicitUntypedSerializer(Class<?> runtime
* Method that will try to construct a value serializer; and if
* one is successfully created, cache it for reuse.
*/
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> type)
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawType)
throws JsonMappingException
{
{
JavaType type = _config.constructType(rawType);
JsonSerializer<Object> ser;
try {
ser = _createUntypedSerializer(_config.constructType(type));
ser = _createUntypedSerializer(type);
} catch (IllegalArgumentException iae) {
/* We better only expose checked exceptions, since those
* are what caller is expected to handle
Expand Down Expand Up @@ -1155,8 +1156,15 @@ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type)
protected JsonSerializer<Object> _createUntypedSerializer(JavaType type)
throws JsonMappingException
{
// 17-Feb-2013, tatu: Used to call deprecated method (that passed property)
return (JsonSerializer<Object>)_serializerFactory.createSerializer(this, type);
/* 27-Mar-2015, tatu: Wish I knew exactly why/what, but [databind#738]
* can be prevented by synchronizing on cache (not on 'this', however,
* since there's one instance per serialization).
* Perhaps not-yet-resolved instance might be exposed too early to callers.
*/
synchronized (_serializerCache) {
// 17-Feb-2013, tatu: Used to call deprecated method (that passed property)
return (JsonSerializer<Object>)_serializerFactory.createSerializer(this, type);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public HasSubTypes getHasSubTypes() {
*/

public void testRepeatedly() throws Exception {
final int COUNT = 50;
final int COUNT = 2000;
for (int i = 0; i < COUNT; i++) {
runOnce(i, COUNT);
}
Expand Down Expand Up @@ -88,10 +88,8 @@ public String call() throws Exception {
JsonNode wrapped = tree.get("hasSubTypes");

if (!wrapped.has("one")) {
System.out.println("JSON wrong: "+json);
throw new IllegalStateException("Round #"+round+"/"+max+" ; missing property 'one', source: "+json);
}
System.out.println("JSON fine: "+json);
}
}

Expand Down

0 comments on commit ec1820d

Please sign in to comment.