Apache Lucene open-source search software
LUCENE-8720: fix int overflow in NameIntCacheLRU
Mike McCandlessc1bea96cf9c6
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 27ba1eda145..954953164dd 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -22,6 +22,9 @@ Bug fixes* LUCENE-8712: Polygon2D does not detect crossings through segment edges.(Ignacio Vera)+* LUCENE-8720: NameIntCacheLRU (in the facets module) had an int+ overflow bug that disabled cleaning of the cache (Russell A Brown)+Improvements* LUCENE-8673: Use radix partitioning when merging dimensional points insteaddiff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/LruTaxonomyWriterCache.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/LruTaxonomyWriterCache.javaindex bab29f6453a..68588c5aba2 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/LruTaxonomyWriterCache.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/LruTaxonomyWriterCache.java@@ -112,7 +112,7 @@ public class LruTaxonomyWriterCache implements TaxonomyWriterCache {// visible to us we need to make sure that the changes have been// committed and we reopen the reader. Because this is a slow// operation, we don't delete entries one-by-one but rather in bulk- // (put() removes the 2/3rd oldest entries).+ // (put() removes the 1/3rd oldest entries).if (ret) {cache.makeRoomLRU();}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/NameIntCacheLRU.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/NameIntCacheLRU.javaindex 25f27999e47..29f6fad9a3a 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/NameIntCacheLRU.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/NameIntCacheLRU.java@@ -109,13 +109,13 @@ class NameIntCacheLRU {* if anything was removed, false otherwise.** See comment in DirectoryTaxonomyWriter.addToCache(CategoryPath, int) for an- * explanation why we clean 2/3rds of the cache, and not just one entry.+ * explanation why we clean 1/3rd of the cache, and not just one entry.*/boolean makeRoomLRU() {if (!isCacheFull()) {return false;}- int n = cache.size() - (2*maxCacheSize)/3;+ int n = cache.size() - (int)((2L*maxCacheSize)/3);if (n<=0) {return false;}