Program: 17239
Project: 17239
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public <T>T invoke(K key,EntryProcessor<K,V,T> entryProcessor,Object... arguments){
  ensureOpen();
  if (key == null) {
    throw new NullPointerException();
  }
  if (entryProcessor == null) {
    throw new NullPointerException();
  }
  long start=statisticsEnabled() ? System.nanoTime() : 0;
  T result=null;
  lockManager.lock(key);
  try {
    long now=System.currentTimeMillis();
    RICacheEventDispatcher<K,V> dispatcher=new RICacheEventDispatcher<K,V>();
    Object internalKey=keyConverter.toInternal(key);
    RICachedValue cachedValue=entries.get(internalKey);
    if (statisticsEnabled()) {
      if (cachedValue == null) {
        statistics.increaseCacheMisses(1);
      }
 else {
        statistics.increaseCacheHits(1);
      }
    }
    if (statisticsEnabled()) {
      statistics.addGetTimeNano(System.nanoTime() - start);
    }
    start=statisticsEnabled() ? System.nanoTime() : 0;
    EntryProcessorEntry entry=new EntryProcessorEntry(key,cachedValue,now,dispatcher);
    try {
      result=entryProcessor.process(entry,arguments);
    }
 catch (    Throwable t) {
      throw new CacheException(t);
    }
    Duration duration;
    long expiryTime;
switch (entry.operation) {
case NONE:
      break;
case CREATE:
    RIEntry<K,V> e=new RIEntry<K,V>(key,entry.value);
  writeCacheEntry(e);
try {
  duration=expiryPolicy.getExpiryForCreatedEntry(e);
}
 catch (Throwable t) {
  duration=getDefaultDuration();
}
expiryTime=duration.getAdjustedTime(now);
cachedValue=new RICachedValue(valueConverter.toInternal(entry.value),now,expiryTime);
if (cachedValue.isExpiredAt(now)) {
V previousValue=valueConverter.fromInternal(cachedValue.get());
dispatcher.addEvent(CacheEntryExpiredListener.class,new RICacheEntryEvent<K,V>(this,key,previousValue,EXPIRED));
}
entries.put(internalKey,cachedValue);
dispatcher.addEvent(CacheEntryCreatedListener.class,new RICacheEntryEvent<K,V>(this,key,entry.value,CREATED));
if (statisticsEnabled()) {
statistics.increaseCachePuts(1);
statistics.addPutTimeNano(System.nanoTime() - start);
}
break;
case UPDATE:
V oldValue=valueConverter.fromInternal(cachedValue.get());
e=new RIEntry<K,V>(key,entry.value,oldValue);
writeCacheEntry(e);
try {
duration=expiryPolicy.getExpiryForModifiedEntry(e);
if (duration != null) {
expiryTime=duration.getAdjustedTime(now);
cachedValue.setExpiryTime(expiryTime);
}
}
 catch (Throwable t) {
}
cachedValue.setInternalValue(valueConverter.toInternal(entry.value),now);
dispatcher.addEvent(CacheEntryUpdatedListener.class,new RICacheEntryEvent<K,V>(this,key,entry.value,oldValue,UPDATED));
if (statisticsEnabled()) {
statistics.increaseCachePuts(1);
statistics.addPutTimeNano(System.nanoTime() - start);
}
break;
case REMOVE:
deleteCacheEntry(key);
oldValue=valueConverter.fromInternal(cachedValue.get());
entries.remove(internalKey);
dispatcher.addEvent(CacheEntryRemovedListener.class,new RICacheEntryEvent<K,V>(this,key,oldValue,REMOVED));
if (statisticsEnabled()) {
statistics.increaseCacheRemovals(1);
statistics.addRemoveTimeNano(System.nanoTime() - start);
}
break;
default :
break;
}
dispatcher.dispatch(listenerRegistrations);
}
  finally {
lockManager.unLock(key);
}
return result;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public <T>T invoke(K key,EntryProcessor<K,V,T> entryProcessor,Object... arguments){
  ensureOpen();
  if (key == null) {
    throw new NullPointerException();
  }
  if (entryProcessor == null) {
    throw new NullPointerException();
  }
  long start=statisticsEnabled() ? System.nanoTime() : 0;
  T result=null;
  lockManager.lock(key);
  try {
    long now=System.currentTimeMillis();
    RICacheEventDispatcher<K,V> dispatcher=new RICacheEventDispatcher<K,V>();
    Object internalKey=keyConverter.toInternal(key);
    RICachedValue cachedValue=entries.get(internalKey);
    if (statisticsEnabled()) {
      if (cachedValue == null) {
        statistics.increaseCacheMisses(1);
      }
 else {
        statistics.increaseCacheHits(1);
      }
    }
    if (statisticsEnabled()) {
      statistics.addGetTimeNano(System.nanoTime() - start);
    }
    start=statisticsEnabled() ? System.nanoTime() : 0;
    EntryProcessorEntry entry=new EntryProcessorEntry(key,cachedValue,now,dispatcher);
    try {
      result=entryProcessor.process(entry,arguments);
    }
 catch (    Throwable t) {
      throw new CacheException(t);
    }
    Duration duration;
    long expiryTime;
switch (entry.operation) {
case NONE:
      break;
case CREATE:
    RIEntry<K,V> e=new RIEntry<K,V>(key,entry.value);
  writeCacheEntry(e);
try {
  duration=expiryPolicy.getExpiryForCreatedEntry(e);
}
 catch (Throwable t) {
  duration=getDefaultDuration();
}
expiryTime=duration.getAdjustedTime(now);
cachedValue=new RICachedValue(valueConverter.toInternal(entry.value),now,expiryTime);
if (cachedValue.isExpiredAt(now)) {
V previousValue=valueConverter.fromInternal(cachedValue.get());
dispatcher.addEvent(CacheEntryExpiredListener.class,new RICacheEntryEvent<K,V>(this,key,previousValue,EXPIRED));
}
entries.put(internalKey,cachedValue);
dispatcher.addEvent(CacheEntryCreatedListener.class,new RICacheEntryEvent<K,V>(this,key,entry.value,CREATED));
if (statisticsEnabled()) {
statistics.increaseCachePuts(1);
statistics.addPutTimeNano(System.nanoTime() - start);
}
break;
case UPDATE:
V oldValue=valueConverter.fromInternal(cachedValue.get());
e=new RIEntry<K,V>(key,entry.value,oldValue);
writeCacheEntry(e);
try {
duration=expiryPolicy.getExpiryForModifiedEntry(e);
if (duration != null) {
expiryTime=duration.getAdjustedTime(now);
cachedValue.setExpiryTime(expiryTime);
}
}
 catch (Throwable t) {
}
cachedValue.setInternalValue(valueConverter.toInternal(entry.value),now);
dispatcher.addEvent(CacheEntryUpdatedListener.class,new RICacheEntryEvent<K,V>(this,key,entry.value,oldValue,UPDATED));
if (statisticsEnabled()) {
statistics.increaseCachePuts(1);
statistics.addPutTimeNano(System.nanoTime() - start);
}
break;
case REMOVE:
deleteCacheEntry(key);
oldValue=cachedValue == null ? null : valueConverter.fromInternal(cachedValue.get());
entries.remove(internalKey);
dispatcher.addEvent(CacheEntryRemovedListener.class,new RICacheEntryEvent<K,V>(this,key,oldValue,REMOVED));
if (statisticsEnabled()) {
statistics.increaseCacheRemovals(1);
statistics.addRemoveTimeNano(System.nanoTime() - start);
}
break;
default :
break;
}
dispatcher.dispatch(listenerRegistrations);
}
  finally {
lockManager.unLock(key);
}
return result;
}