File tree Expand file tree Collapse file tree
main/java/org/apache/arrow/vector
test/java/org/apache/arrow/vector Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1405,7 +1405,8 @@ public final int getTotalValueLengthUpToIndex(int index) {
14051405 }
14061406
14071407 protected final void handleSafe (int index , int dataLength ) {
1408- final long targetCapacity = roundUpToMultipleOf16 ((long ) index * ELEMENT_SIZE + dataLength );
1408+ // The view buffer stores one fixed-width view per value; payload bytes are allocated separately.
1409+ final long targetCapacity = roundUpToMultipleOf16 (((long ) index + 1 ) * ELEMENT_SIZE );
14091410 if (viewBuffer .capacity () < targetCapacity ) {
14101411 reallocViewBuffer (targetCapacity );
14111412 }
Original file line number Diff line number Diff line change @@ -540,6 +540,26 @@ public void testSizeOfViewBufferElements() {
540540 }
541541 }
542542
543+ @ ParameterizedTest
544+ @ MethodSource ({"vectorCreatorProvider" })
545+ public void testSetSafeEmptyValueAtViewBufferBoundary (
546+ Function <BufferAllocator , BaseVariableWidthViewVector > vectorCreator ) {
547+ try (final BaseVariableWidthViewVector vector = vectorCreator .apply (allocator )) {
548+ final byte [] emptyValue = new byte [0 ];
549+ vector .allocateNew ();
550+ final int valueCapacity = vector .getValueCapacity ();
551+
552+ for (int i = 0 ; i <= valueCapacity ; i ++) {
553+ vector .setSafe (i , emptyValue );
554+ }
555+
556+ vector .setValueCount (valueCapacity + 1 );
557+ assertTrue (vector .getValueCapacity () > valueCapacity );
558+ assertEquals (0 , vector .getValueLength (valueCapacity ));
559+ assertArrayEquals (emptyValue , vector .get (valueCapacity ));
560+ }
561+ }
562+
543563 @ Test
544564 public void testNullableVarType1 () {
545565
You can’t perform that action at this time.
0 commit comments