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 Dec 3, 2021
1 parent d55a917 commit 6fd2213
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 @@ -202,7 +202,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 @@ -181,7 +181,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 @@ -190,7 +190,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 6fd2213

Please sign in to comment.