Issue #6974 - fix bug in ByteBufferPool implementations

If an allocation size of 0 was requested bucketFor would throw.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-11-26 17:30:14 +11:00
parent c19921e60f
commit 377d0d131e
2 changed files with 3 additions and 3 deletions

View File

@ -197,7 +197,7 @@ public class ArrayByteBufferPool extends AbstractByteBufferPool implements Dumpa
protected int bucketFor(int capacity)
{
return (int)Math.ceil((double)capacity / getCapacityFactor());
return Math.max((int)Math.ceil((double)capacity / getCapacityFactor()), 1);
}
protected int capacityFor(int bucket)

View File

@ -176,7 +176,7 @@ public class MappedByteBufferPool extends AbstractByteBufferPool implements Dump
}
if (index >= 0)
{
Bucket bucket = buckets.get(index);
Bucket bucket = buckets.remove(index);
// Null guard in case this.clear() is called concurrently.
if (bucket != null)
bucket.clear();
@ -185,7 +185,7 @@ public class MappedByteBufferPool extends AbstractByteBufferPool implements Dump
protected int bucketFor(int capacity)
{
return (int)Math.ceil((double)capacity / getCapacityFactor());
return Math.max((int)Math.ceil((double)capacity / getCapacityFactor()), 1);
}
protected int capacityFor(int bucket)