Skip to content

Commit ec1820d

Browse files
committed
Fix #738
1 parent 48617c8 commit ec1820d

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,8 @@ Antibrumm@github:
215215
Francisco A. Lozano (flozano@github)
216216
* Contributed fix for #703 (see above)
217217
(2.5.2)
218+
219+
Dylan Scott (dylanscott@github)
220+
* Reported #738: #738: @JsonTypeInfo non-deterministically ignored in 2.5.1 (concurrency
221+
issue)
222+
(2.5.2)

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Project: jackson-databind
1919
(reported by jkochaniak@github)
2020
#733: MappingIterator should move past errors or not return hasNext() == true
2121
(reported by Lorrin N, lorrin@github)
22+
#738: @JsonTypeInfo non-deterministically ignored in 2.5.1 (concurrency issue)
23+
(reported by Dylan S, dylanscott@github)
2224
- Improvement to handling of custom `ValueInstantiator` for delegating mode; no more NPE
2325
if `getDelegateCreator()` returns null
2426

src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,12 +1111,13 @@ protected JsonSerializer<Object> _findExplicitUntypedSerializer(Class<?> runtime
11111111
* Method that will try to construct a value serializer; and if
11121112
* one is successfully created, cache it for reuse.
11131113
*/
1114-
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> type)
1114+
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawType)
11151115
throws JsonMappingException
1116-
{
1116+
{
1117+
JavaType type = _config.constructType(rawType);
11171118
JsonSerializer<Object> ser;
11181119
try {
1119-
ser = _createUntypedSerializer(_config.constructType(type));
1120+
ser = _createUntypedSerializer(type);
11201121
} catch (IllegalArgumentException iae) {
11211122
/* We better only expose checked exceptions, since those
11221123
* are what caller is expected to handle
@@ -1155,8 +1156,15 @@ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type)
11551156
protected JsonSerializer<Object> _createUntypedSerializer(JavaType type)
11561157
throws JsonMappingException
11571158
{
1158-
// 17-Feb-2013, tatu: Used to call deprecated method (that passed property)
1159-
return (JsonSerializer<Object>)_serializerFactory.createSerializer(this, type);
1159+
/* 27-Mar-2015, tatu: Wish I knew exactly why/what, but [databind#738]
1160+
* can be prevented by synchronizing on cache (not on 'this', however,
1161+
* since there's one instance per serialization).
1162+
* Perhaps not-yet-resolved instance might be exposed too early to callers.
1163+
*/
1164+
synchronized (_serializerCache) {
1165+
// 17-Feb-2013, tatu: Used to call deprecated method (that passed property)
1166+
return (JsonSerializer<Object>)_serializerFactory.createSerializer(this, type);
1167+
}
11601168
}
11611169

11621170
/**

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public HasSubTypes getHasSubTypes() {
5656
*/
5757

5858
public void testRepeatedly() throws Exception {
59-
final int COUNT = 50;
59+
final int COUNT = 2000;
6060
for (int i = 0; i < COUNT; i++) {
6161
runOnce(i, COUNT);
6262
}
@@ -88,10 +88,8 @@ public String call() throws Exception {
8888
JsonNode wrapped = tree.get("hasSubTypes");
8989

9090
if (!wrapped.has("one")) {
91-
System.out.println("JSON wrong: "+json);
9291
throw new IllegalStateException("Round #"+round+"/"+max+" ; missing property 'one', source: "+json);
9392
}
94-
System.out.println("JSON fine: "+json);
9593
}
9694
}
9795

0 commit comments

Comments
 (0)