Fix IndexOutOfBoundsException raised when numHeapArenas and numDirectArenas differ

- Fixes #1227
This commit is contained in:
Trustin Lee 2013-04-03 22:15:34 +09:00
parent 8fef511390
commit baf9ecfe7b

View File

@ -87,8 +87,10 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator {
private final AtomicInteger index = new AtomicInteger();
@Override
protected PoolThreadCache initialValue() {
int idx = Math.abs(index.getAndIncrement() % heapArenas.length);
return new PoolThreadCache(heapArenas[idx], directArenas[idx]);
int idx = index.getAndIncrement();
int heapIdx = Math.abs(idx % heapArenas.length);
int directIdx = Math.abs(idx % directArenas.length);
return new PoolThreadCache(heapArenas[heapIdx], directArenas[directIdx]);
}
};