Skip to content

Commit

Permalink
[ARROW-105] Fix BaseAllocator.java NPE when assertions are disabled
Browse files Browse the repository at this point in the history
When verifying memory using verifyAllocator() method, BaseAllocator throws NPE
if assertions are disabled.

Fixing this issue by checking first if assertion are disabled
  • Loading branch information
laurentgo committed Apr 15, 2016
1 parent 7b2153b commit 6d2f61c
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ protected BaseAllocator(

}

@Override
public void assertOpen() {
if (AssertionUtil.ASSERT_ENABLED) {
if (isClosed) {
Expand Down Expand Up @@ -287,6 +288,7 @@ public Reservation() {
}
}

@Override
public boolean add(final int nBytes) {
assertOpen();

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

@Override
public ArrowBuf allocateBuffer() {
assertOpen();

Expand All @@ -319,14 +322,17 @@ public ArrowBuf allocateBuffer() {
return arrowBuf;
}

@Override
public int getSize() {
return nBytes;
}

@Override
public boolean isUsed() {
return used;
}

@Override
public boolean isClosed() {
return closed;
}
Expand Down Expand Up @@ -364,6 +370,7 @@ public void close() {
closed = true;
}

@Override
public boolean reserve(int nBytes) {
assertOpen();

Expand Down Expand Up @@ -509,6 +516,7 @@ public synchronized void close() {

}

@Override
public String toString() {
final Verbosity verbosity = logger.isTraceEnabled() ? Verbosity.LOG_WITH_STACKTRACE
: Verbosity.BASIC;
Expand All @@ -523,6 +531,7 @@ public String toString() {
*
* @return A Verbose string of current allocator state.
*/
@Override
public String toVerboseString() {
final StringBuilder sb = new StringBuilder();
print(sb, 0, Verbosity.LOG_WITH_STACKTRACE);
Expand Down Expand Up @@ -575,13 +584,12 @@ void verifyAllocator() {
* when any problems are found
*/
private void verifyAllocator(final IdentityHashMap<UnsafeDirectLittleEndian, BaseAllocator> buffersSeen) {
synchronized (DEBUG_LOCK) {

// The remaining tests can only be performed if we're in debug mode.
if (!DEBUG) {
return;
}
// The remaining tests can only be performed if we're in debug mode.
if (!DEBUG) {
return;
}

synchronized (DEBUG_LOCK) {
final long allocated = getAllocatedMemory();

// verify my direct descendants
Expand Down

0 comments on commit 6d2f61c

Please sign in to comment.