Skip to content

Commit

Permalink
ARROW-8305: [Java] ExtensionTypeVector should make sure underlyingVec…
Browse files Browse the repository at this point in the history
…tor not null

Related to [ARROW-8305](https://issues.apache.org/jira/browse/ARROW-8305).

In ExtensionTypeVector seems not check nullability for underlyingVector, and it will throw exception when it is null in some api like accept/reset/getField etc.

it's better to do null check when create ExtensionTypeVector rather than when really use it.

Closes #6798 from tianchen92/ARROW-8305

Authored-by: tianchen <niki.lj@alibaba-inc.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
tianchen92 authored and lidavidm committed Apr 3, 2020
1 parent f5f09d5 commit 502e6fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.OutOfMemoryException;
import org.apache.arrow.util.Preconditions;
import org.apache.arrow.vector.compare.VectorVisitor;
import org.apache.arrow.vector.complex.reader.FieldReader;
import org.apache.arrow.vector.ipc.message.ArrowFieldNode;
Expand Down Expand Up @@ -50,6 +51,7 @@ public abstract class ExtensionTypeVector<T extends BaseValueVector & FieldVecto
*/
public ExtensionTypeVector(String name, BufferAllocator allocator, T underlyingVector) {
super(allocator);
Preconditions.checkNotNull(underlyingVector, "underlyingVector can not be null.");
this.name = name;
this.underlyingVector = underlyingVector;
}
Expand Down
Expand Up @@ -17,6 +17,9 @@

package org.apache.arrow.vector.types.pojo;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -155,6 +158,19 @@ public void readUnderlyingType() throws IOException {
}
}

@Test
public void testNullCheck() {
NullPointerException e = assertThrows(NullPointerException.class,
() -> {
try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
final ExtensionTypeVector vector = new UuidVector("uuid", allocator, null)) {
vector.getField();
vector.allocateNewSafe();
}
});
assertTrue(e.getMessage().contains("underlyingVector can not be null."));
}

static class UuidType extends ExtensionType {

@Override
Expand Down

0 comments on commit 502e6fe

Please sign in to comment.