1
1
package com .fasterxml .jackson .databind .deser ;
2
2
3
3
import java .util .HashMap ;
4
+ import java .util .concurrent .locks .ReentrantLock ;
4
5
5
6
import com .fasterxml .jackson .annotation .JsonFormat ;
6
7
import com .fasterxml .jackson .databind .*;
@@ -52,6 +53,12 @@ public final class DeserializerCache
52
53
protected final HashMap <JavaType , JsonDeserializer <Object >> _incompleteDeserializers
53
54
= new HashMap <JavaType , JsonDeserializer <Object >>(8 );
54
55
56
+
57
+ /**
58
+ * We hold an explicit lock while creating deserializers to avoid creating duplicates.
59
+ */
60
+ private final ReentrantLock _incompleteDeserializersLock = new ReentrantLock ();
61
+
55
62
/*
56
63
/**********************************************************
57
64
/* Life-cycle
@@ -246,7 +253,9 @@ protected JsonDeserializer<Object> _createAndCacheValueDeserializer(Deserializat
246
253
* limitations necessary to ensure that only completely initialized ones
247
254
* are visible and used.
248
255
*/
249
- synchronized (_incompleteDeserializers ) {
256
+ try {
257
+ _incompleteDeserializersLock .lock ();
258
+
250
259
// Ok, then: could it be that due to a race condition, deserializer can now be found?
251
260
JsonDeserializer <Object > deser = _findCachedDeserializer (type );
252
261
if (deser != null ) {
@@ -269,6 +278,8 @@ protected JsonDeserializer<Object> _createAndCacheValueDeserializer(Deserializat
269
278
_incompleteDeserializers .clear ();
270
279
}
271
280
}
281
+ } finally {
282
+ _incompleteDeserializersLock .unlock ();
272
283
}
273
284
}
274
285
0 commit comments