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

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git


The following commit(s) were added to refs/heads/master by this push:
     new 6a89929e Deep-copy bootstrap arguments array in BootstrapMethod.copy 
(#516)
6a89929e is described below

commit 6a89929ec834b403c320c3d5bc15e9a3c3ea104b
Author: Dexter.k <[email protected]>
AuthorDate: Sat Jul 4 18:39:20 2026 +0000

    Deep-copy bootstrap arguments array in BootstrapMethod.copy (#516)
---
 .../org/apache/bcel/classfile/BootstrapMethod.java |  6 ++-
 .../bcel/classfile/BootstrapMethodCopyTest.java    | 46 ++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java 
b/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
index 60eb55f6..5633f1d1 100644
--- a/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
+++ b/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
@@ -51,7 +51,7 @@ public class BootstrapMethod implements Cloneable {
      * @param c Source to copy.
      */
     public BootstrapMethod(final BootstrapMethod c) {
-        this(c.getBootstrapMethodRef(), c.getBootstrapArguments());
+        this(c.getBootstrapMethodRef(), c.getBootstrapArguments().clone());
     }
 
     /**
@@ -91,7 +91,9 @@ public class BootstrapMethod implements Cloneable {
      */
     public BootstrapMethod copy() {
         try {
-            return (BootstrapMethod) clone();
+            final BootstrapMethod c = (BootstrapMethod) clone();
+            c.bootstrapArguments = bootstrapArguments.clone();
+            return c;
         } catch (final CloneNotSupportedException ignore) {
             // TODO should this throw?
         }
diff --git 
a/src/test/java/org/apache/bcel/classfile/BootstrapMethodCopyTest.java 
b/src/test/java/org/apache/bcel/classfile/BootstrapMethodCopyTest.java
new file mode 100644
index 00000000..dfca3a97
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/BootstrapMethodCopyTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.bcel.classfile;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests that {@link BootstrapMethod} copies do not share the mutable {@code 
bootstrapArguments} array with their source.
+ */
+class BootstrapMethodCopyTest {
+
+    @Test
+    void testCopyConstructorDoesNotShareArguments() {
+        final BootstrapMethod original = new BootstrapMethod(1, new int[] {10, 
20, 30});
+        final BootstrapMethod copy = new BootstrapMethod(original);
+        copy.getBootstrapArguments()[0] = 999;
+        assertArrayEquals(new int[] {10, 20, 30}, 
original.getBootstrapArguments());
+    }
+
+    @Test
+    void testCopyDoesNotShareArguments() {
+        final BootstrapMethod original = new BootstrapMethod(1, new int[] {10, 
20, 30});
+        final BootstrapMethod copy = original.copy();
+        copy.getBootstrapArguments()[0] = 999;
+        assertArrayEquals(new int[] {10, 20, 30}, 
original.getBootstrapArguments());
+    }
+}

Reply via email to