Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ public boolean addAll(final Collection<? extends E> coll) {
@Override
public boolean addAll(final int index, final Collection<? extends E> coll) {
final Node<E> node = getNode(index, true);
if (coll.isEmpty()) {
return false;
}
for (final E e : coll) {
addNodeBefore(node, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ public boolean addAll(final Collection<? extends E> coll) {
@Override
public boolean addAll(final int index, final Collection<? extends E> coll) {
final Node<E> node = getNode(index, true);
if (coll.isEmpty()) {
return false;
}
for (final E e : coll) {
addNodeBefore(node, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,21 @@ void testFullListSerialization() throws IOException, ClassNotFoundException {
assertEquals(size, list2.size(), "Both lists are same size");
}

/**
* Tests that {@link List#addAll(Collection)} and {@link List#addAll(int, Collection)}
* return false and leave the list unchanged when the collection to add is empty.
*/
@Test
void testListAddAllEmptyReturnsFalse() {
if (!isAddSupported()) {
return;
}
final List<E> list = makeObject();
assertFalse(list.addAll(Collections.<E>emptyList()), "addAll of an empty collection must return false");
assertFalse(list.addAll(0, Collections.<E>emptyList()), "addAll(index) of an empty collection must return false");
assertTrue(list.isEmpty());
}

/**
* Tests {@link List#add(int,Object)}.
*/
Expand Down
Loading