Correctly update size of the Stack before doing any validation in Recycler (#9731)
Motivation: We null out the element in the array after we decrement the current size of the Stack but not directly write back the updated size to the stored field. This is problematic as we do some validation before we write it back and so may never do so if the validation fails. This then later can lead to have null objects returned where not expected Modifications: Update size directly after null out object Result: No more unexpected null value possible
This commit is contained in:
parent
9976ab7fe8
commit
7c85c9ea0b
@ -518,12 +518,16 @@ public abstract class Recycler<T> {
|
||||
size --;
|
||||
DefaultHandle ret = elements[size];
|
||||
elements[size] = null;
|
||||
// As we already set the element[size] to null we also need to store the updated size before we do
|
||||
// any validation. Otherwise we may see a null value when later try to pop again without a new element
|
||||
// added before.
|
||||
this.size = size;
|
||||
|
||||
if (ret.lastRecycledId != ret.recycleId) {
|
||||
throw new IllegalStateException("recycled multiple times");
|
||||
}
|
||||
ret.recycleId = 0;
|
||||
ret.lastRecycledId = 0;
|
||||
this.size = size;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user