@@ -194,15 +194,16 @@ public JSONArray(Iterable<?> iter) {
194194 /**
195195 * Construct a JSONArray from another JSONArray. This is a shallow copy.
196196 *
197- * @param collection
198- * A Collection .
197+ * @param array
198+ * A array .
199199 */
200200 public JSONArray (JSONArray array ) {
201201 if (array == null ) {
202202 this .myArrayList = new ArrayList <Object >();
203203 } else {
204- this .myArrayList = new ArrayList <Object >(array .length ());
205- this .addAll (array .myArrayList );
204+ // shallow copy directly the internal array lists as any wrapping
205+ // should have been done already in the original JSONArray
206+ this .myArrayList = new ArrayList <Object >(array .myArrayList );
206207 }
207208 }
208209
@@ -1213,7 +1214,7 @@ public JSONArray putAll(Collection<?> collection) {
12131214 * Put an Iterable's elements in to the JSONArray.
12141215 *
12151216 * @param iter
1216- * A Collection .
1217+ * An Iterable .
12171218 * @return this.
12181219 */
12191220 public JSONArray putAll (Iterable <?> iter ) {
@@ -1229,7 +1230,9 @@ public JSONArray putAll(Iterable<?> iter) {
12291230 * @return this.
12301231 */
12311232 public JSONArray putAll (JSONArray array ) {
1232- this .addAll (array .myArrayList );
1233+ // directly copy the elements from the source array to this one
1234+ // as all wrapping should have been done already in the source.
1235+ this .myArrayList .addAll (array .myArrayList );
12331236 return this ;
12341237 }
12351238
@@ -1606,8 +1609,9 @@ private void addAll(Iterable<?> iter) {
16061609 * Add an array's elements to the JSONArray.
16071610 *
16081611 * @param array
1609- * Array. If the parameter passed is null, or not an array, an
1610- * exception will be thrown.
1612+ * Array. If the parameter passed is null, or not an array,
1613+ * JSONArray, Collection, or Iterable, an exception will be
1614+ * thrown.
16111615 *
16121616 * @throws JSONException
16131617 * If not an array or if an array value is non-finite number.
@@ -1622,7 +1626,10 @@ private void addAll(Object array) throws JSONException {
16221626 this .put (JSONObject .wrap (Array .get (array , i )));
16231627 }
16241628 } else if (array instanceof JSONArray ) {
1625- this .addAll (((JSONArray )array ).myArrayList );
1629+ // use the built in array list `addAll` as all object
1630+ // wrapping should have been completed in the original
1631+ // JSONArray
1632+ this .myArrayList .addAll (((JSONArray )array ).myArrayList );
16261633 } else if (array instanceof Collection ) {
16271634 this .addAll ((Collection <?>)array );
16281635 } else if (array instanceof Iterable ) {
0 commit comments