Skip to content

Commit

Permalink
Issue #6974 - fix bug in ByteBufferPool implementations
Browse files Browse the repository at this point in the history
If an allocation size of 0 was requested bucketFor would throw.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Nov 26, 2021
1 parent c19921e commit 377d0d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected void releaseMemory(boolean direct)

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected void releaseMemory(boolean direct)
}
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();
Expand All @@ -185,7 +185,7 @@ protected void releaseMemory(boolean direct)

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)
Expand Down

0 comments on commit 377d0d1

Please sign in to comment.