This is an automated email from the ASF dual-hosted git repository.

viirya pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 5e71a2a6 MINOR: Add explicit exception when no more buffer can be read 
when loading buffers (#649)
5e71a2a6 is described below

commit 5e71a2a67ebb215099f3d8d532df54f6cb1c537c
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Tue Mar 4 09:42:57 2025 -0800

    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.
---
 vector/src/main/java/org/apache/arrow/vector/VectorLoader.java | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/vector/src/main/java/org/apache/arrow/vector/VectorLoader.java 
b/vector/src/main/java/org/apache/arrow/vector/VectorLoader.java
index ecd3fb91..9b9a8903 100644
--- a/vector/src/main/java/org/apache/arrow/vector/VectorLoader.java
+++ b/vector/src/main/java/org/apache/arrow/vector/VectorLoader.java
@@ -122,6 +122,10 @@ public class VectorLoader {
         (int) (variadicBufferLayoutCount + 
TypeLayout.getTypeBufferCount(field.getType()));
     List<ArrowBuf> ownBuffers = new ArrayList<>(bufferLayoutCount);
     for (int j = 0; j < bufferLayoutCount; j++) {
+      if (!buffers.hasNext()) {
+        throw new IllegalArgumentException(
+            "no more buffers for field " + field + ". Expected " + 
bufferLayoutCount);
+      }
       ArrowBuf nextBuf = buffers.next();
       // for vectors without nulls, the buffer is empty, so there is no need 
to decompress it.
       ArrowBuf bufferToAdd =

Reply via email to