-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Description
Original issue created by DanGLow on 2014-05-22 at 05:18 PM
Hi,
This bug was originally discovered here: elastic/elasticsearch#6268, but I have traced it down into an issue with an overflowing int and long comparison in LocalCache.java eviction logic. The following is the eviction code at https://github.com/google/guava/blob/master/guava/src/com/google/common/cache/LocalCache.java#L2665
@GuardedBy("Segment.this")
void evictEntries() {
if (!map.evictsBySize()) {
return;
}
drainRecencyQueue();
while (totalWeight > maxSegmentWeight) {
ReferenceEntry<K, V> e = getNextEvictable();
if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) {
throw new AssertionError();
}
}
}
'totalWeight' is defined as an int, while 'maxSegmentWeight' is a long. If 'maxSegmentWeight' is set to any value int.MAX_VALUE or greater, then this check
while (totalWeight > maxSegmentWeight) {
will never be true, since 'totalWeight' will overflow, and the eviction code will never run.