ehcache / ehcache-jcache

The Ehcache 2.x implementation of JSR107 (JCACHE)
Other
91 stars 48 forks source link

Potential Unreleased Lock #53

Open ananmika opened 8 years ago

ananmika commented 8 years ago

In V load(K key) method of org.ehcache.jcache.JCache class ehcache.acquireWriteLockOnKey(key) lock doesn't released when value exists. Lock must be acquired if value not exists in cache.

V load(K key) {
        V value;
        final Element e = ehcache.get(key);
        if(e != null) {
            return (V)e.getObjectValue();
        }
        try {
            ehcache.acquireWriteLockOnKey(key);
            try {
                value = cacheLoader.load(key);
            } catch (Exception ex) {
                throw new CacheLoaderException(ex);
            }
            if(value != null) {
                putWithoutWriter(key, value);
            }
        } finally{
            ehcache.releaseWriteLockOnKey(key);
        }
        return value;
    }