Fix NPE that was encounter by debugger (will never happen in real code). (#8992)
Motivation: We synchronize on the chunk.arena when produce the String returned by PoolSubpage.toString() which may raise a NPE when chunk == null. Chunk == null for the head of the linked-list and so a NPE may raised by a debugger. This NPE can never happen in real code tho as we never access toString() of the head. Modifications: Add null checks and so fix the possible NPE Result: No NPE when using a debugger and inspect the PooledByteBufAllocator.
This commit is contained in:
parent
f7359aa742
commit
a2b85a306d
|
@ -204,16 +204,24 @@ final class PoolSubpage<T> implements PoolSubpageMetric {
|
||||||
final int maxNumElems;
|
final int maxNumElems;
|
||||||
final int numAvail;
|
final int numAvail;
|
||||||
final int elemSize;
|
final int elemSize;
|
||||||
synchronized (chunk.arena) {
|
if (chunk == null) {
|
||||||
if (!this.doNotDestroy) {
|
// This is the head so there is no need to synchronize at all as these never change.
|
||||||
doNotDestroy = false;
|
doNotDestroy = true;
|
||||||
// Not used for creating the String.
|
maxNumElems = 0;
|
||||||
maxNumElems = numAvail = elemSize = -1;
|
numAvail = 0;
|
||||||
} else {
|
elemSize = -1;
|
||||||
doNotDestroy = true;
|
} else {
|
||||||
maxNumElems = this.maxNumElems;
|
synchronized (chunk.arena) {
|
||||||
numAvail = this.numAvail;
|
if (!this.doNotDestroy) {
|
||||||
elemSize = this.elemSize;
|
doNotDestroy = false;
|
||||||
|
// Not used for creating the String.
|
||||||
|
maxNumElems = numAvail = elemSize = -1;
|
||||||
|
} else {
|
||||||
|
doNotDestroy = true;
|
||||||
|
maxNumElems = this.maxNumElems;
|
||||||
|
numAvail = this.numAvail;
|
||||||
|
elemSize = this.elemSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +235,11 @@ final class PoolSubpage<T> implements PoolSubpageMetric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int maxNumElements() {
|
public int maxNumElements() {
|
||||||
|
if (chunk == null) {
|
||||||
|
// It's the head.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (chunk.arena) {
|
synchronized (chunk.arena) {
|
||||||
return maxNumElems;
|
return maxNumElems;
|
||||||
}
|
}
|
||||||
|
@ -234,6 +247,11 @@ final class PoolSubpage<T> implements PoolSubpageMetric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int numAvailable() {
|
public int numAvailable() {
|
||||||
|
if (chunk == null) {
|
||||||
|
// It's the head.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (chunk.arena) {
|
synchronized (chunk.arena) {
|
||||||
return numAvail;
|
return numAvail;
|
||||||
}
|
}
|
||||||
|
@ -241,6 +259,11 @@ final class PoolSubpage<T> implements PoolSubpageMetric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int elementSize() {
|
public int elementSize() {
|
||||||
|
if (chunk == null) {
|
||||||
|
// It's the head.
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (chunk.arena) {
|
synchronized (chunk.arena) {
|
||||||
return elemSize;
|
return elemSize;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user