Program: 17224
Project: 17224
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public void removeAll(){
  ensureOpen();
  int size=(statisticsEnabled()) ? entries.size() : 0;
  long now=System.currentTimeMillis();
  CacheException exception=null;
  HashSet<K> lockedKeys=new HashSet<K>();
  RICacheEventDispatcher<K,V> dispatcher=new RICacheEventDispatcher<K,V>();
  try {
    boolean isWriteThrough=configuration.isWriteThrough() && cacheWriter != null;
    HashSet<K> keysToDelete=new HashSet<K>();
    Iterator<Map.Entry<Object,RICachedValue>> iterator=entries.iterator();
    while (iterator.hasNext()) {
      Map.Entry<Object,RICachedValue> entry=iterator.next();
      Object internalKey=entry.getKey();
      K key=keyConverter.fromInternal(internalKey);
      lockManager.lock(key);
      lockedKeys.add(key);
      if (isWriteThrough) {
        keysToDelete.add(key);
      }
    }
    if (isWriteThrough) {
      try {
        cacheWriter.deleteAll(keysToDelete);
      }
 catch (      Exception e) {
        if (!(e instanceof CacheWriterException)) {
          exception=new CacheWriterException("String_Node_Str",e);
        }
      }
    }
    for (    K key : lockedKeys) {
      if (!keysToDelete.contains(key)) {
        Object internalKey=keyConverter.toInternal(key);
        RICachedValue cachedValue=entries.remove(internalKey);
        V value=valueConverter.fromInternal(cachedValue.get());
        if (cachedValue.isExpiredAt(now)) {
          dispatcher.addEvent(CacheEntryExpiredListener.class,new RICacheEntryEvent<K,V>(this,key,value,EXPIRED));
        }
 else {
          dispatcher.addEvent(CacheEntryRemovedListener.class,new RICacheEntryEvent<K,V>(this,key,value,REMOVED));
        }
      }
    }
  }
  finally {
    for (    K key : lockedKeys) {
      lockManager.unLock(key);
    }
  }
  dispatcher.dispatch(listenerRegistrations);
  if (statisticsEnabled()) {
    statistics.increaseCacheRemovals(size);
  }
  if (exception != null) {
    throw exception;
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void removeAll(){
  ensureOpen();
  int size=(statisticsEnabled()) ? entries.size() : 0;
  long now=System.currentTimeMillis();
  CacheException exception=null;
  HashSet<K> lockedKeys=new HashSet<K>();
  RICacheEventDispatcher<K,V> dispatcher=new RICacheEventDispatcher<K,V>();
  try {
    boolean isWriteThrough=configuration.isWriteThrough() && cacheWriter != null;
    HashSet<K> keysToDelete=new HashSet<K>();
    Iterator<Map.Entry<Object,RICachedValue>> iterator=entries.iterator();
    while (iterator.hasNext()) {
      Map.Entry<Object,RICachedValue> entry=iterator.next();
      Object internalKey=entry.getKey();
      K key=keyConverter.fromInternal(internalKey);
      lockManager.lock(key);
      lockedKeys.add(key);
      if (isWriteThrough) {
        keysToDelete.add(key);
      }
    }
    if (isWriteThrough && keysToDelete.size() > 0) {
      try {
        cacheWriter.deleteAll(keysToDelete);
      }
 catch (      Exception e) {
        if (!(e instanceof CacheWriterException)) {
          exception=new CacheWriterException("String_Node_Str",e);
        }
      }
    }
    for (    K key : lockedKeys) {
      if (!keysToDelete.contains(key)) {
        Object internalKey=keyConverter.toInternal(key);
        RICachedValue cachedValue=entries.remove(internalKey);
        V value=valueConverter.fromInternal(cachedValue.get());
        if (cachedValue.isExpiredAt(now)) {
          dispatcher.addEvent(CacheEntryExpiredListener.class,new RICacheEntryEvent<K,V>(this,key,value,EXPIRED));
        }
 else {
          dispatcher.addEvent(CacheEntryRemovedListener.class,new RICacheEntryEvent<K,V>(this,key,value,REMOVED));
        }
      }
    }
  }
  finally {
    for (    K key : lockedKeys) {
      lockManager.unLock(key);
    }
  }
  dispatcher.dispatch(listenerRegistrations);
  if (statisticsEnabled()) {
    statistics.increaseCacheRemovals(size);
  }
  if (exception != null) {
    throw exception;
  }
}