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

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new b046d1b2bc GROOVY-11702: Tuple changes related to its backing array
b046d1b2bc is described below

commit b046d1b2bcbbddd59ea3d6abdf5de24a671ce51a
Author: Choosechee <sweetbayou...@gmail.com>
AuthorDate: Wed Jun 18 13:08:50 2025 -0500

    GROOVY-11702: Tuple changes related to its backing array
---
 src/main/java/groovy/lang/Tuple.java | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main/java/groovy/lang/Tuple.java 
b/src/main/java/groovy/lang/Tuple.java
index da8f31ea1a..ffa490cfb3 100644
--- a/src/main/java/groovy/lang/Tuple.java
+++ b/src/main/java/groovy/lang/Tuple.java
@@ -22,13 +22,15 @@ import 
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
 
 import java.io.Serializable;
 import java.util.AbstractList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
+import java.util.RandomAccess;
 
 /**
  * Represents a list of Objects.
  */
-public class Tuple<E> extends AbstractList<E> implements Serializable, 
Cloneable, Comparable<Tuple<E>> {
+public class Tuple<E> extends AbstractList<E> implements Serializable, 
Cloneable, Comparable<Tuple<E>>, RandomAccess {
     private static final long serialVersionUID = -6707770506387821031L;
     private final E[] contents;
 
@@ -52,9 +54,25 @@ public class Tuple<E> extends AbstractList<E> implements 
Serializable, Cloneable
         return contents.length;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public E[] toArray() {
-        return contents;
+        int size = size();
+        E[] copy = (E[]) new Object[size];
+        System.arraycopy(contents, 0, copy, 0, size);
+        return copy;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T[] toArray(T[] a) {
+        int size = size();
+        if (a.length < size)
+            a = (T[]) new Object[size];
+
+        System.arraycopy(contents, 0, a, 0, size);
+        Arrays.fill(a, size, a.length, null);
+        return a;
     }
 
     @SuppressWarnings("unchecked")

Reply via email to