Skip to content

Commit

Permalink
Revert "Fix #4561 (revert #4430)" -- i.e. go back to modified #4430 f…
Browse files Browse the repository at this point in the history
…or 2.17.2 (#4568)
  • Loading branch information
cowtowncoder authored Jun 6, 2024
1 parent b89886a commit d0cd01b
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.databind.deser;

import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.*;
Expand Down Expand Up @@ -52,6 +53,15 @@ public final class DeserializerCache
protected final HashMap<JavaType, JsonDeserializer<Object>> _incompleteDeserializers
= new HashMap<JavaType, JsonDeserializer<Object>>(8);


/**
* We hold an explicit lock while creating deserializers to avoid creating duplicates.
* Guards {@link #_incompleteDeserializers}.
*
* @since 2.17
*/
private final ReentrantLock _incompleteDeserializersLock = new ReentrantLock();

/*
/**********************************************************
/* Life-cycle
Expand Down Expand Up @@ -162,10 +172,9 @@ public JsonDeserializer<Object> findValueDeserializer(DeserializationContext ctx
// If not, need to request factory to construct (or recycle)
deser = _createAndCacheValueDeserializer(ctxt, factory, propertyType);
if (deser == null) {
/* Should we let caller handle it? Let's have a helper method
* decide it; can throw an exception, or return a valid
* deserializer
*/
// Should we let caller handle it? Let's have a helper method
// decide it; can throw an exception, or return a valid
// deserializer
deser = _handleUnknownValueDeserializer(ctxt, propertyType);
}
}
Expand Down Expand Up @@ -204,9 +213,8 @@ public boolean hasValueDeserializerFor(DeserializationContext ctxt,
DeserializerFactory factory, JavaType type)
throws JsonMappingException
{
/* Note: mostly copied from findValueDeserializer, except for
* handling of unknown types
*/
// Note: mostly copied from findValueDeserializer, except for
// handling of unknown types
JsonDeserializer<Object> deser = _findCachedDeserializer(type);
if (deser == null) {
deser = _createAndCacheValueDeserializer(ctxt, factory, type);
Expand Down Expand Up @@ -245,7 +253,8 @@ protected JsonDeserializer<Object> _createAndCacheValueDeserializer(Deserializat
// Only one thread to construct deserializers at any given point in time;
// limitations necessary to ensure that only completely initialized ones
// are visible and used.
synchronized (_incompleteDeserializers) {
_incompleteDeserializersLock.lock();
try {
// Ok, then: could it be that due to a race condition, deserializer can now be found?
JsonDeserializer<Object> deser = _findCachedDeserializer(type);
if (deser != null) {
Expand All @@ -268,6 +277,8 @@ protected JsonDeserializer<Object> _createAndCacheValueDeserializer(Deserializat
_incompleteDeserializers.clear();
}
}
} finally {
_incompleteDeserializersLock.unlock();
}
}

Expand Down

0 comments on commit d0cd01b

Please sign in to comment.