Skip to content

Commit

Permalink
Merge pull request #907 from hexetia/fix-901
Browse files Browse the repository at this point in the history
Fix a bug when calling JSONArray.addAll() with Collection as Object
  • Loading branch information
stleary authored Nov 13, 2024
2 parents e7e52da + 14e9cdc commit 2ee5bf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ private void addAll(Object array, boolean wrap, int recursionDepth, JSONParserCo
// JSONArray
this.myArrayList.addAll(((JSONArray)array).myArrayList);
} else if (array instanceof Collection) {
this.addAll((Collection<?>)array, wrap, recursionDepth);
this.addAll((Collection<?>)array, wrap, recursionDepth, jsonParserConfiguration);
} else if (array instanceof Iterable) {
this.addAll((Iterable<?>)array, wrap);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/json/junit/JSONArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public void verifyPutAll() {
jsonArray.length(),
len);

// collection as object
@SuppressWarnings("RedundantCast")
Object myListAsObject = (Object) myList;
jsonArray.putAll(myListAsObject);

for (int i = 0; i < myList.size(); i++) {
assertEquals("collection elements should be equal",
myList.get(i),
Expand Down

0 comments on commit 2ee5bf1

Please sign in to comment.