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

Fokko pushed a commit to branch parquet-1.18.x
in repository https://gitbox.apache.org/repos/asf/parquet-java.git


The following commit(s) were added to refs/heads/parquet-1.18.x by this push:
     new a3501b616 `BytesInput.copy(BytesInput)` should return a copy (#3729)
a3501b616 is described below

commit a3501b61622be52c9620c0ed93480417f27b5600
Author: Aaron Niskode-Dossett <[email protected]>
AuthorDate: Mon Aug 31 11:15:31 2026 -0500

    `BytesInput.copy(BytesInput)` should return a copy (#3729)
    
    * BytesInput.copy(BytesInput) should return a copy
    
    * make tests clearer
    
    * Remove unsafe BytesInput toByteArray override
---
 .../main/java/org/apache/parquet/bytes/BytesInput.java   | 15 ---------------
 .../java/org/apache/parquet/bytes/TestBytesInput.java    | 16 +++++++---------
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git 
a/parquet-common/src/main/java/org/apache/parquet/bytes/BytesInput.java 
b/parquet-common/src/main/java/org/apache/parquet/bytes/BytesInput.java
index ca139d924..d7d8aa6fc 100644
--- a/parquet-common/src/main/java/org/apache/parquet/bytes/BytesInput.java
+++ b/parquet-common/src/main/java/org/apache/parquet/bytes/BytesInput.java
@@ -690,21 +690,6 @@ public abstract class BytesInput {
       return java.nio.ByteBuffer.wrap(in, offset, length);
     }
 
-    /**
-     * Zero-copy override: returns the backing array directly when fully used,
-     * skipping the base-class BAOS allocation + copy on every decompressor 
call.
-     * Returning the mutable array is safe — the base class already exposes a
-     * mutable {@code BAOS.getBuf()}.
-     */
-    @SuppressWarnings("deprecation")
-    @Override
-    public byte[] toByteArray() {
-      if (offset == 0 && length == in.length) {
-        return in;
-      }
-      return Arrays.copyOfRange(in, offset, offset + length);
-    }
-
     @Override
     public long size() {
       return length;
diff --git 
a/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java 
b/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java
index a80c874fa..18e9b02ef 100644
--- a/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java
+++ b/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java
@@ -123,16 +123,14 @@ public class TestBytesInput {
 
   @ParameterizedTest(name = "{0}")
   @MethodSource("parameters")
-  public void testFromByteArrayToByteArrayZeroCopy(ByteBufferAllocator 
innerAllocator) throws IOException {
+  public void testCopyDoesNotAliasSourceBytes(ByteBufferAllocator 
innerAllocator) throws IOException {
     initAllocator(innerAllocator);
-    // Full array (offset=0, length=array.length): toByteArray() returns the 
backing array directly
-    byte[] data = new byte[1000];
-    RANDOM.nextBytes(data);
-    BytesInput bi = BytesInput.from(data, 0, data.length);
-    byte[] result = bi.toByteArray();
-    assertThat(result)
-        .as("toByteArray() should return the backing array when offset=0 and 
length=full")
-        .isSameAs(data);
+    byte[] source = {'a'};
+    BytesInput copied = BytesInput.copy(BytesInput.from(source));
+
+    source[0] = 'b';
+
+    assertThat(copied.toByteArray()).isEqualTo(new byte[] {'a'});
   }
 
   @ParameterizedTest(name = "{0}")

Reply via email to