Skip to content

Commit

Permalink
fix(core): ListNode.addAll(ListNode.value()) generates a Concurrent…
Browse files Browse the repository at this point in the history
…ModificationException
  • Loading branch information
Siroshun09 committed Mar 15, 2024
1 parent 4bb6082 commit 89da0ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ public void add(@Nullable Object value) {

@Override
public void addAll(@NotNull Collection<?> collection) {
for (var element : collection) {
if (collection.isEmpty()) {
return;
}

for (var element : collection.toArray()) { // We need to create an array to prevent ConcurrentModificationException
this.backing.add(Node.fromObject(element));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ protected Stream<NodeTestCase<ListNode>> nodeTestCases() {
},
(initial, modified) -> assertEquals(List.of(StringValue.fromString("a"), new IntValue(1), BooleanValue.TRUE), modified.value())
),
nodeTest(
"ListNode#addAll(Collection) by ListNode#value",
ListNode.create(List.of("a", "b", "c")),
node -> {
node.addAll(node.value());
return node;
},
(initial, modified) -> {
assertEquals(6, modified.size());
assertEquals(List.of("a", "b", "c", "a", "b", "c"), modified.asList(String.class));
}
),
nodeTest(
"ListNode#addAll(ListNode)",
ListNode.create(List.of("a", "b", "c")),
Expand Down

0 comments on commit 89da0ca

Please sign in to comment.