Skip to content

Commit 4f3ac8d

Browse files
authored
Revert "Fix #4561 (revert #4430) (#4562)"
This reverts commit b89886a.
1 parent b89886a commit 4f3ac8d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

release-notes/VERSION-2.x

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ Project: jackson-databind
88

99
-
1010

11-
2.17.2 (not yet released)
12-
13-
#4561: Issues using jackson-databind 2.17.1 with Reactor
14-
(reported by @wdallastella)
15-
1611
2.17.1 (04-May-2024)
1712

1813
#4428: `ByteBuddy` scope went beyond `test` in version 2.17.0

src/main/java/com/fasterxml/jackson/databind/deser/DeserializerCache.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fasterxml.jackson.databind.deser;
22

33
import java.util.HashMap;
4+
import java.util.concurrent.locks.ReentrantLock;
45

56
import com.fasterxml.jackson.annotation.JsonFormat;
67
import com.fasterxml.jackson.databind.*;
@@ -52,6 +53,12 @@ public final class DeserializerCache
5253
protected final HashMap<JavaType, JsonDeserializer<Object>> _incompleteDeserializers
5354
= new HashMap<JavaType, JsonDeserializer<Object>>(8);
5455

56+
57+
/**
58+
* We hold an explicit lock while creating deserializers to avoid creating duplicates.
59+
*/
60+
private final ReentrantLock _incompleteDeserializersLock = new ReentrantLock();
61+
5562
/*
5663
/**********************************************************
5764
/* Life-cycle
@@ -242,10 +249,12 @@ protected JsonDeserializer<Object> _createAndCacheValueDeserializer(Deserializat
242249
DeserializerFactory factory, JavaType type)
243250
throws JsonMappingException
244251
{
245-
// Only one thread to construct deserializers at any given point in time;
246-
// limitations necessary to ensure that only completely initialized ones
247-
// are visible and used.
248-
synchronized (_incompleteDeserializers) {
252+
/* Only one thread to construct deserializers at any given point in time;
253+
* limitations necessary to ensure that only completely initialized ones
254+
* are visible and used.
255+
*/
256+
_incompleteDeserializersLock.lock();
257+
try {
249258
// Ok, then: could it be that due to a race condition, deserializer can now be found?
250259
JsonDeserializer<Object> deser = _findCachedDeserializer(type);
251260
if (deser != null) {
@@ -268,6 +277,8 @@ protected JsonDeserializer<Object> _createAndCacheValueDeserializer(Deserializat
268277
_incompleteDeserializers.clear();
269278
}
270279
}
280+
} finally {
281+
_incompleteDeserializersLock.unlock();
271282
}
272283
}
273284

0 commit comments

Comments
 (0)