Skip to content

Commit 6d2f61c

Browse files
committed
[ARROW-105] Fix BaseAllocator.java NPE when assertions are disabled
When verifying memory using verifyAllocator() method, BaseAllocator throws NPE if assertions are disabled. Fixing this issue by checking first if assertion are disabled
1 parent 7b2153b commit 6d2f61c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

java/memory/src/main/java/org/apache/arrow/memory/BaseAllocator.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected BaseAllocator(
9999

100100
}
101101

102+
@Override
102103
public void assertOpen() {
103104
if (AssertionUtil.ASSERT_ENABLED) {
104105
if (isClosed) {
@@ -287,6 +288,7 @@ public Reservation() {
287288
}
288289
}
289290

291+
@Override
290292
public boolean add(final int nBytes) {
291293
assertOpen();
292294

@@ -308,6 +310,7 @@ public boolean add(final int nBytes) {
308310
return true;
309311
}
310312

313+
@Override
311314
public ArrowBuf allocateBuffer() {
312315
assertOpen();
313316

@@ -319,14 +322,17 @@ public ArrowBuf allocateBuffer() {
319322
return arrowBuf;
320323
}
321324

325+
@Override
322326
public int getSize() {
323327
return nBytes;
324328
}
325329

330+
@Override
326331
public boolean isUsed() {
327332
return used;
328333
}
329334

335+
@Override
330336
public boolean isClosed() {
331337
return closed;
332338
}
@@ -364,6 +370,7 @@ public void close() {
364370
closed = true;
365371
}
366372

373+
@Override
367374
public boolean reserve(int nBytes) {
368375
assertOpen();
369376

@@ -509,6 +516,7 @@ public synchronized void close() {
509516

510517
}
511518

519+
@Override
512520
public String toString() {
513521
final Verbosity verbosity = logger.isTraceEnabled() ? Verbosity.LOG_WITH_STACKTRACE
514522
: Verbosity.BASIC;
@@ -523,6 +531,7 @@ public String toString() {
523531
*
524532
* @return A Verbose string of current allocator state.
525533
*/
534+
@Override
526535
public String toVerboseString() {
527536
final StringBuilder sb = new StringBuilder();
528537
print(sb, 0, Verbosity.LOG_WITH_STACKTRACE);
@@ -575,13 +584,12 @@ void verifyAllocator() {
575584
* when any problems are found
576585
*/
577586
private void verifyAllocator(final IdentityHashMap<UnsafeDirectLittleEndian, BaseAllocator> buffersSeen) {
578-
synchronized (DEBUG_LOCK) {
579-
580-
// The remaining tests can only be performed if we're in debug mode.
581-
if (!DEBUG) {
582-
return;
583-
}
587+
// The remaining tests can only be performed if we're in debug mode.
588+
if (!DEBUG) {
589+
return;
590+
}
584591

592+
synchronized (DEBUG_LOCK) {
585593
final long allocated = getAllocatedMemory();
586594

587595
// verify my direct descendants

0 commit comments

Comments
 (0)