Skip to content

Commit 3677619

Browse files
sstricklcommit-bot@chromium.org
authored andcommitted
[vm/corelib] Fix ConcurrentModificationError for empty addAll.
Since we only add elements if the iterator is non-empty, we shouldn't get a ConcurrentModificationError if both the iterator and receiver are the same empty EfficientLengthIterator. Fixes #42011 TEST=New regression test added that fails without the sdk change. Fixed: 42011 Change-Id: Ib5259c8f043cc8277d2fea407d1f64a24430c4d3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173901 Reviewed-by: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Tess Strickland <[email protected]>
1 parent b64550e commit 3677619

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

sdk/lib/_internal/vm/lib/growable_array.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ class _GrowableList<T> extends ListBase<T> {
211211
var cap = _capacity;
212212
// Pregrow if we know iterable.length.
213213
var iterLen = iterable.length;
214+
if (iterLen == 0) {
215+
return;
216+
}
214217
var newLen = len + iterLen;
215218
if (newLen > cap) {
216219
do {

tests/corelib/regress_42011_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Regression test for https://github.com/dart-lang/sdk/issues/42011
6+
main() {
7+
var a = [];
8+
// No elements are added, so should not get a ConcurrentModificationError.
9+
a.addAll(a);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Regression test for https://github.com/dart-lang/sdk/issues/42011
6+
main() {
7+
var a = [];
8+
// No elements are added, so should not get a ConcurrentModificationError.
9+
a.addAll(a);
10+
}

0 commit comments

Comments
 (0)