Add more information to unexpected assertion failure

Issue: #4532

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=208968252
This commit is contained in:
olly 2018-08-16 05:12:32 -07:00 committed by Oliver Woodman
parent 80f5b7e7b2
commit 94c7fbbc24

View file

@ -118,8 +118,18 @@ public final class DefaultAllocator implements Allocator {
}
for (Allocation allocation : allocations) {
// Weak sanity check that the allocation probably originated from this pool.
Assertions.checkArgument(allocation.data == initialAllocationBlock
|| allocation.data.length == individualAllocationSize);
if (allocation.data != initialAllocationBlock
&& allocation.data.length != individualAllocationSize) {
throw new IllegalArgumentException(
"Unexpected allocation: "
+ System.identityHashCode(allocation.data)
+ ", "
+ System.identityHashCode(initialAllocationBlock)
+ ", "
+ allocation.data.length
+ ", "
+ individualAllocationSize);
}
availableAllocations[availableCount++] = allocation;
}
allocatedCount -= allocations.length;