Ensure clearWith lambda is deleting all the list item, else we will get an infinite loop. This specific error will help to figure out what is happening.

This commit is contained in:
Benoit Marty 2022-06-28 11:56:41 +02:00
parent 69920a6e46
commit 9866bfefed
1 changed files with 4 additions and 0 deletions

View File

@ -30,7 +30,11 @@ internal fun RealmObject.assertIsManaged() {
*/
internal fun <T> RealmList<T>.clearWith(delete: (T) -> Unit) {
while (!isEmpty()) {
val previousSize = size
first()?.let { delete.invoke(it) }
if (previousSize != size + 1) {
error("`clearWith` MUST delete all elements of the RealmList")
}
}
}