#260 CustomConverterContainer puts null results in cache

Dozer v5.2.2

CustomConverterContainer.getCustomConverter put null results in the DozerCache. The DozerCache.put method i synchronized which causes Threadblocking.
I've patched it and tried it locally and all the blocking threads disappeared from DozerCache.
The fix is to check the result for null before putting in the cache.
Since the code checks for a null value in the cache before trying to locate the customconverter the change should be safe to use.

public Class getCustomConverter(Class<?> srcClass, Class<?> destClass, Cache converterByDestTypeCache) {
if (converters.isEmpty()) {
return null;

// Check cache first
final Object cacheKey = CacheKeyFactory.createKey(destClass, srcClass);
Class result = (Class) converterByDestTypeCache.get(cacheKey);
if (result != null) {
return result;

// Let's see if the incoming class is a primitive:
final Class src = ClassUtils.primitiveToWrapper(srcClass);
final Class dest = ClassUtils.primitiveToWrapper(destClass);

// Otherwise, loop through custom converters and look for a match. Also, store the result in the cache
for (CustomConverterDescription customConverter : converters) {
final Class classA = customConverter.getClassA();
final Class classB = customConverter.getClassB();

// we check to see if the destination class is the same as classA defined in the converter mapping xml.
// we next check if the source class is the same as classA defined in the converter mapping xml.
// we also to check to see if it is assignable to either. We then perform these checks in the other direction for classB
if ((classA.isAssignableFrom(dest) && classB.isAssignableFrom(src))
|| (classA.isAssignableFrom(src) && classB.isAssignableFrom(dest))) {
result = customConverter.getType();
if (result != null) {
converterByDestTypeCache.put(cacheKey, result);
return result;


  • Peter Liljenberg

    • milestone: 1049123 --> 898417
  • Peter Liljenberg

  • dmitry (lv)

    dmitry (lv) - 2010-05-29
    • milestone: 898417 --> Dozer v5.2.2
    • assigned_to: nobody --> buzdin
    • status: open --> closed-fixed
  • dmitry (lv)

    dmitry (lv) - 2010-05-29

    Solved a bit differently. We need null entries in cache not to resolve once more in next mappings. Instead it is possible to check id key is in cache and based on that return either null or converter type.
    Issue with synchronization should be solved.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks