mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:31:58 +00:00
[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 https://github.com/dart-lang/sdk/issues/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 <lrn@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Tess Strickland <sstrickl@google.com>
This commit is contained in:
parent
b64550eaff
commit
367761987b
|
@ -211,6 +211,9 @@ class _GrowableList<T> extends ListBase<T> {
|
|||
var cap = _capacity;
|
||||
// Pregrow if we know iterable.length.
|
||||
var iterLen = iterable.length;
|
||||
if (iterLen == 0) {
|
||||
return;
|
||||
}
|
||||
var newLen = len + iterLen;
|
||||
if (newLen > cap) {
|
||||
do {
|
||||
|
|
10
tests/corelib/regress_42011_test.dart
Normal file
10
tests/corelib/regress_42011_test.dart
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Regression test for https://github.com/dart-lang/sdk/issues/42011
|
||||
main() {
|
||||
var a = [];
|
||||
// No elements are added, so should not get a ConcurrentModificationError.
|
||||
a.addAll(a);
|
||||
}
|
10
tests/corelib_2/regress_42011_test.dart
Normal file
10
tests/corelib_2/regress_42011_test.dart
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Regression test for https://github.com/dart-lang/sdk/issues/42011
|
||||
main() {
|
||||
var a = [];
|
||||
// No elements are added, so should not get a ConcurrentModificationError.
|
||||
a.addAll(a);
|
||||
}
|
Loading…
Reference in a new issue