axreldable commented on code in PR #1099:
URL: https://github.com/apache/arrow-java/pull/1099#discussion_r3032968241


##########
vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java:
##########
@@ -1127,4 +1128,90 @@ private void writeIntValues(UnionLargeListWriter writer, 
int[] values) {
     }
     writer.endList();
   }
+
+  @Test
+  public void testSetValueCountRejectsNegativeChildValueCount() {
+    try (final LargeListVector vector = LargeListVector.empty("list", 
allocator)) {
+      vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
+      vector.allocateNew();
+
+      // Write a negative value into the offset buffer to simulate a corrupted 
offset.
+      // The Preconditions check should reject any negative childValueCount.
+      vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, -1L);
+      vector.setLastSet(0);
+
+      assertThrows(
+          IllegalArgumentException.class,
+          () -> vector.setValueCount(1),
+          "setValueCount should reject negative childValueCount");
+    }
+  }
+
+  @Test
+  public void testSetValueCountRejectsOverflowChildValueCount() {
+    try (final LargeListVector vector = LargeListVector.empty("list", 
allocator)) {
+      vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
+      vector.allocateNew();
+
+      // Write a value exceeding Integer.MAX_VALUE into the offset buffer
+      vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, (long) 
Integer.MAX_VALUE + 1L);
+      vector.setLastSet(0);
+
+      assertThrows(
+          IllegalArgumentException.class,
+          () -> vector.setValueCount(1),
+          "setValueCount should reject childValueCount exceeding 
Integer.MAX_VALUE");
+    }
+  }
+
+  @Test
+  public void testSetValueCountAcceptsZeroChildValueCount() {
+    try (final LargeListVector vector = LargeListVector.empty("list", 
allocator)) {
+      vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
+      vector.allocateNew();
+
+      // childValueCount = 0 when valueCount = 0 (no elements)
+      vector.setValueCount(0);
+      assertEquals(0, vector.getValueCount());
+    }
+  }
+
+  @Test
+  public void testSetValueCountAcceptsValidChildValueCount() {
+    try (final LargeListVector vector = LargeListVector.empty("list", 
allocator)) {
+      vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
+      vector.allocateNew();
+
+      // Write a valid childValueCount (5) into the offset buffer
+      vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, 5L);
+      vector.setLastSet(0);
+      vector.setValueCount(1);
+      assertEquals(1, vector.getValueCount());
+    }
+  }
+
+  @Test
+  public void testSetValueCountAcceptsMaxIntChildValueCount() {
+    try (final LargeListVector vector = LargeListVector.empty("list", 
allocator)) {
+      vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
+      vector.allocateNew();
+
+      // Write Integer.MAX_VALUE into the offset buffer to verify the upper 
boundary is inclusive.
+      // The Preconditions check should accept this value (not throw 
IllegalArgumentException).
+      // The child vector may throw OversizedAllocationException due to memory 
limits,
+      // which is expected and unrelated to the precondition validation.
+      vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, (long) 
Integer.MAX_VALUE);

Review Comment:
   nit: `Casting 'Integer.MAX_VALUE' to 'long' is redundant`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to