Check for null before returing a chunk from the pool.
Since references can be queued in another thread, the first entry in the pool could have been queued after processPoolLocked. Check for null and create a new chunk if the check fails.
This commit is contained in:
@@ -114,14 +114,17 @@ class ByteArrayBuilder {
|
|||||||
length = DEFAULT_CAPACITY;
|
length = DEFAULT_CAPACITY;
|
||||||
}
|
}
|
||||||
synchronized (sPool) {
|
synchronized (sPool) {
|
||||||
// Process any queued references so that sPool does not contain
|
// Process any queued references and remove them from the pool.
|
||||||
// dead entries.
|
|
||||||
processPoolLocked();
|
processPoolLocked();
|
||||||
if (!sPool.isEmpty()) {
|
if (!sPool.isEmpty()) {
|
||||||
return sPool.removeFirst().get();
|
Chunk c = sPool.removeFirst().get();
|
||||||
} else {
|
// The first item may have been queued after processPoolLocked
|
||||||
return new Chunk(length);
|
// so check for null.
|
||||||
|
if (c != null) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return new Chunk(length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user