Skip to content

Commit 5e71a2a

Browse files
authored
MINOR: Add explicit exception when no more buffer can be read when loading buffers (#649)
## What's Changed When `VectorLoader` tries to load buffers (i.e., `loadBuffers`), it has detect on the error case that some buffers are not consumed. But another error that the number of buffers is less than expected is not handled for now. Once it is happened, users will get `java.util.NoSuchElementException` which is not easy to understand. This patch adds an explicit exception for such case. See more discussion at #648.
1 parent 26e14f0 commit 5e71a2a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

vector/src/main/java/org/apache/arrow/vector/VectorLoader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ private void loadBuffers(
122122
(int) (variadicBufferLayoutCount + TypeLayout.getTypeBufferCount(field.getType()));
123123
List<ArrowBuf> ownBuffers = new ArrayList<>(bufferLayoutCount);
124124
for (int j = 0; j < bufferLayoutCount; j++) {
125+
if (!buffers.hasNext()) {
126+
throw new IllegalArgumentException(
127+
"no more buffers for field " + field + ". Expected " + bufferLayoutCount);
128+
}
125129
ArrowBuf nextBuf = buffers.next();
126130
// for vectors without nulls, the buffer is empty, so there is no need to decompress it.
127131
ArrowBuf bufferToAdd =

0 commit comments

Comments
 (0)