Describe the bug
Currently, in RandomReplacementCache the below code is being used to randomly remove elements from the cache
cache.remove(random.nextInt(CACHE_SIZE + 1));
The random.nextInt function here can end up generating 5 sometimes whereas the collection has the size=5 which would mean the indices are only from 0-4.
This would then end up in an IndexOutOfBoundsException.
Expected behavior
IndexOutOfBounds Exception should not be seen
Proposed solution
The nextInt function should just be passed with CACHE_SIZE and not CACHE_SIZE+1
Please assign the issue to me.
Will push the fix for this.
Describe the bug Currently, in RandomReplacementCache the below code is being used to randomly remove elements from the cache
cache.remove(random.nextInt(CACHE_SIZE + 1));
The random.nextInt function here can end up generating 5 sometimes whereas the collection has the size=5 which would mean the indices are only from 0-4. This would then end up in an IndexOutOfBoundsException.
Expected behavior IndexOutOfBounds Exception should not be seen
Proposed solution The nextInt function should just be passed with CACHE_SIZE and not CACHE_SIZE+1
Please assign the issue to me. Will push the fix for this.