Skip to content

Commit b98a560

Browse files
liyafan82Pindikura Ravindra
authored andcommitted
ARROW-6117: [Java] Fix the set method of FixedSizeBinaryVector
For the set method, if the parameter is null, it should clear the validity bit. However, the current implementation throws a NullPointerException. Closes apache#4995 from liyafan82/fly_0802_fixset and squashes the following commits: b6e650c <liyafan82> Fix the set method of FixedSizeBinaryVector Authored-by: liyafan82 <fan_li_ya@foxmail.com> Signed-off-by: Pindikura Ravindra <ravindra@dremio.com>
1 parent efeecfb commit b98a560

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎java/vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.arrow.vector;
1919

2020
import org.apache.arrow.memory.BufferAllocator;
21+
import org.apache.arrow.util.Preconditions;
2122
import org.apache.arrow.vector.complex.impl.FixedSizeBinaryReaderImpl;
2223
import org.apache.arrow.vector.complex.reader.FieldReader;
2324
import org.apache.arrow.vector.holders.FixedSizeBinaryHolder;
@@ -163,6 +164,7 @@ public int getByteWidth() {
163164
/** Sets the value at index to the provided one. */
164165
public void set(int index, byte[] value) {
165166
assert index >= 0;
167+
Preconditions.checkNotNull(value, "expecting a valid byte array");
166168
assert byteWidth <= value.length;
167169
BitVectorHelper.setValidityBitToOne(validityBuffer, index);
168170
valueBuffer.setBytes(index * byteWidth, value, 0, byteWidth);

‎java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.arrow.vector;
1919

2020
import static org.junit.Assert.*;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2122

2223
import org.apache.arrow.memory.BufferAllocator;
2324
import org.apache.arrow.vector.holders.FixedSizeBinaryHolder;
@@ -149,6 +150,18 @@ public void testSetUsingByteArray() {
149150
}
150151
}
151152

153+
@Test
154+
public void testSetUsingNull() {
155+
final byte[] value = null;
156+
for (int i = 0; i < numValues; i++) {
157+
final int index = i;
158+
Exception e = assertThrows(NullPointerException.class, () -> {
159+
vector.set(index, value);
160+
});
161+
assertEquals("expecting a valid byte array", e.getMessage());
162+
}
163+
}
164+
152165
@Test
153166
public void testSetUsingHolder() {
154167
for (int i = 0; i < numValues; i++) {

0 commit comments

Comments
 (0)