From fb381cb6c7c9e1183dfeb88dd94c25134049ece9 Mon Sep 17 00:00:00 2001 From: Lucas Bradstreet Date: Thu, 29 Aug 2019 18:02:27 -0700 Subject: [PATCH] MINOR: Fix integer overflow in LRUCacheBenchmark (#7270) The jmh LRUCacheBenchmark will exhibit an int overflow when run on a fast machine: ``` java.lang.ArrayIndexOutOfBoundsException: Index -3648 out of bounds for length 10000 at org.apache.kafka.jmh.cache.LRUCacheBenchmark.testCachePerformance(LRUCacheBenchmark.java:70) at org.apache.kafka.jmh.cache.generated.LRUCacheBenchmark_testCachePerformance_jmhTest.testCachePerformance_thrpt_jmhStub(LRUCacheBenchmark_testCachePerformance_jmhTest.java:119) at org.apache.kafka.jmh.cache.generated.LRUCacheBenchmark_testCachePerformance_jmhTest.testCachePerformance_Throughput(LRUCacheBenchmark_testCachePerformance_jmhTest.java:83) ``` Reviewers: Jason Gustafson --- .../java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java index 7d6597993bf..5b2d004dcd5 100644 --- a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java +++ b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java @@ -52,7 +52,7 @@ public class LRUCacheBenchmark { private LRUCache lruCache; - int counter; + private long counter = 0; @Setup(Level.Trial) public void setUp() { @@ -66,7 +66,7 @@ public class LRUCacheBenchmark { @Benchmark public String testCachePerformance() { counter++; - int index = counter % DISTINCT_KEYS; + int index = (int) (counter % DISTINCT_KEYS); String hashkey = keys[index]; lruCache.put(hashkey, values[index]); return lruCache.get(hashkey);